In this activity you will write a function that composes multiple graphics into a flower.
Assume you have a friend who does not see the graphic below:
You may have said something like "a flower made up of four pink circular petals and a light yellow circular pistil".
circle FunctionThis flower seems to be made up of quite a few circles.
So let's first import or create a circle function that takes a diameter and a color:
def circle(diameter: float, color: Color) -> Graphic
If you don't yet have a circle function in your toolbox, implement one and store it in your toolbox. Check the Simple Snowman activity to learn how to do this.
Now let's import and try the circle function from our toolbox:
Isn't it nice that you can just import circle and use it.
You don't need to worry how it actually works.
Implement the four_petal_flower function to recreate the flower.
Use the specified petal_color and pistil_color colors.
Hint: You only need beside, above, and overlay to compose five circles. You may want to use rotate to slightly simplify your life.
You learned to decompose a graphic, and to compose code that produces that graphic.
You probably created primitive graphics using circle,
and you composed these circles using overlay, and
either above and beside,
or above and rotate,
or beside and rotate.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Four Petal Flower

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 3ec0cab (Tue, 28 Oct 2025 16:56:29 GMT)