At My Fingertips
Rapid Playground
A dot mandala, like the one above, is composed of several rings of dots.
In this activity, we provide you with a function named dot_ring
that creates a ring of dots.
def dot_ring(
ring_diameter: float,
dot_diameter: float,
dot_count: int,
dot_color: Color
) -> Graphic:
The function has four parameters: the diameter of the ring, the diameter of the dots in the ring, the number of dots to place in the ring, and the colors of the dots in the ring. The function returns a graphic of the resulting ring. If you want to find out how to implement a function like that yourself, check out the Simple Rings activity!
Let's create the above dot ring with ring diameter 150 consisting of 9 red dots with diameter 20.
We just created a ring of dots, but a dot mandala consists of many rings.
To compose multiple rings into a graphic,
we can import the compose_multiple
function from the mandala
library.
def compose_multiple(graphics: list[Graphic]) -> Graphic:
This function takes a list of graphics and reduces that list into a single graphic by composing all of the graphics. The first graphic appears in front, the last in the very back.
Moreover, in the center of the mandala there's usually a circle.
Thus, we import the circle
function from the mandala
library as well.
def circle(diameter: int, color: Color) -> Graphic:
The circle
function produces a graphic of the circle with the given diameter
filled in the given color.
Let's use these functions to produce the above graphic:
In a dot mandala, sometimes we want to rotate a ring, like here:
To do this, the dot_ring
function offers a fifth, optional parameter named angle_offset
.
def dot_ring(
ring_diameter: float,
dot_diameter: float,
dot_count: int,
dot_color: Color
angle_offset: float = 0
) -> Graphic:
That parameter can take any value between -1 and 1, to rotate a ring by a fraction of the angle between two dots. A positive value rotates the ring counter-clockwise, a negative value rotates it clockwise.
In the above example, we rotated the blue ring by 0.5, which makes the 9 blue dots fall between the 9 red dots.
For our mandala to look good, we need a nice set of colors. Here is an example.
Below we define constants for each of the above colors
(the leftmost color is named pacific_blue
).
Feel free to find your own set of colors, e.g., by searching the web for "mandala color palettes".
Add as many rings as you like, using colors, counts, and diameters of your choice.
In this activity you practiced calling functions, passing arguments, and constructing lists. On top of that, you may have enjoyed putting together your own beautiful dot mandala.
Note that by manually building a long list of rings you did not really practice the abstraction skills that are central to programming. In programming, we do not really like "repetitive code" (similar lines of code), and we do not like "magic numbers" (all those manually tweaked diameters and dot counts). Ideally, we can find a concise way to describe the same graphic (by using abstraction to extract the similarities and to turn the differences into parameters).
But when constructing art like this mandala,
unlike when writing programs that have specific requirements,
the manual tweaking into not easily abstractable forms,
and the repetitive manual labor,
is part of the experience.
In a way, our convenient dot_ring
function, a pretty neat abstraction,
is counter to the idea of a mandala:
the rings it produces are too precise:
all the dots have precisely the same round shape
and are placed at precisely the right place.
If we drew each dot by hand, we would not be as accurate,
and the mandala would look more authentic.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Dot Mandala
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 19a6bb6 (Mon, 27 Jan 2025 12:33:26 GMT)