At My Fingertips
Rapid Playground
Assume you have a friend who does not see the graphic below:
Yes, it's the Czech flag. And it's made up of two horizontal bands in the colors white and red, with a blue isosceles triangle overlaid and aligned along the left edge.
The Wikipedia page Flag of the Czech Republic includes the following sketch that specifies the shapes:
The colors of the flag are specified using the RGB color model as follows:
Let's define some constants for them. We can create arbitrary colors using the rgb_color function.
Oh! Did you notice that the white is a pure white
(the red, green, and blue lamps are all at their maximum intensity, 255)?
The pytamaro
library already provides a name for a pure white color: white.
Thus, we don't need to create that color but can just import it.
Let's look at our colors by creating a different graphic for each color:
This composition is more challenging than it looks. Would you like some tips?
Creating and composing the two bands is quite straightforward. The blue triangle, though, is quite tricky.
You could compute the side length of an isosceles triangle with a base length of 2 units and a height of 1.5 units. But do you remember the formula for that? And do you know or remember the trigonometry necessary to compute the angle?
Here is an alternative: Compose the blue triangle from two smaller right triangles!
The above sketch clearly shows the two legs (catheti) of the upper triangle: the horizontal leg is 1.5 unit long, the vertical leg is 1 unit long. So you can create the upper triangle with:
triangle(1.5 * unit, unit, 90, czech_blue)
Creating the lower right triangle is more difficult. It seems just to be a flipped version of the upper one, but we have no way to flip (mirror) a graphic. So we have to create another right triangle. Can you do that? (Try flipping the side lengths and rotating the result!)
Once you have the two right triangles, place them above each other.
Finally, overlay the resulting isosceles triangle on top of the two bands. Unfortunately, if you use overlay just like that, the triangle will be centered on the background.
We need the triangle and the background aligned on the left edge. To do that, we can pin both of them, e.g., at their center_left, and then we can compose them.
You learned a way to construct (we prefer the word "compose") the flag of the Czech Republic using the few available primitives of the PyTamaro library.
More generally, you also learned a way to construct
an isosceles triangle given its base and height,
without using any formulas and trigonometry,
by composing two right triangles.
You may want to create a general isosceles_triangle_base_height
function,
and store it in your toolbox,
so you can easily create such triangles without thinking in the future!
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Czech Flag
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy ⢠Platform Version c08406b (Wed, 20 Nov 2024 12:30:00 GMT)