At My Fingertips
Rapid Playground
Let's compose a cute little bird in the so-called "flat design" style.
One way to decompose the bird is to see it as:
The body consist of two squares and two 90-degree circular sectors. The width and height of the body are the same. The shapes of the body and the wing are the same, but the wing has half the width and height of the body. The eye consists of a black pupil centered on a white sclera. The diameter of the sclera is half the width or height of the wing, and the pupil is half the diameter of the sclera. The beak consists of two 90-degree circular sectors. The radius of the upper beak sector is half the width or height of the wing. The radius of the lower beak sector is half that of the upper one, and the lower sector is rotated -90 degrees with respect to the top one.
First, let's import the necessary names. Then let's define names for the colors we need.
Let's create a function to compose the eye:
Now let's implement a function to compose the beak:
Let's implement a function to build the dark-green wing, given the height (note that the width is equal to the height):
Now let's implement a function that creates the light-green body. You may want to overlay the eye on top of the upper right square of the body, and the wing on top of the lower left square. (Alternatively, you may want to compose the body without eye and wing, and later compose these pieces with the overall body. This may be a bit trickier, though.)
Now let's compose the body and the beak into a complete bird. (If you have a body without wing and eye, you also need to add those.)
You may want to change the colors of your bird.
You may want to introduce additional parameters for the colors, so that you can use the same code to build birds of different colors.
You also may want to animate its eye
(e.g., make the pupil smaller and bigger),
or its beak (open/close by changing the angles of the two sectors).
To do the animation, you want to introduce additional parameters
to the functions, so that you can pass in the pupil size and/or beak openness
when you call the bird
function.
You learned how to decompose a graphic, and to create a nice function for each component. Your functions can be developed, tested, and used on their own: for example, you can call your beak function to create a beak for a penguin, or just a beak on its own.
If you want to reuse your functions in other activities, save them in your toolbox (click the tools button at the bottom of the corresponding code cell).
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Flat Design Bird
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)