At My Fingertips

In this activity you will write a function that composes multiple graphics into a flower.

Asking for a Graphic

Assume you have a friend who does not see the graphic below:

four petal flower

You may have said something like "a flower made up of four pink circular petals and a light yellow circular pistil".

We need a circle Function

This 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 PyTamaro iconSimple Snowman activity to learn how to do this.

Now let's import and try the circle function from our toolbox:

Loading...

Isn't it nice that you can just import circle and use it. You don't need to worry how it actually works.

Create the Flower

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.

Loading...

What You Learned

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

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version b744b47 (Tue, 08 Oct 2024 16:30:14 GMT)