At My Fingertips
In this activity we will implement a function called star that will allow us to create n-pointed stars for n larger than 2. This means three-pointed stars, four-pointed stars, five-pointed stars, and so on.
The star function will also take as parameter the size of each vertex and the angle of each vertex. In our implementation, if the angle is too obtuse the results are not acceptable, therefore we will set a maximum_angle of 360 / n for each n being the number of vertices of the star.
Example: for five-pointed stars, the maximum angle is of 360° / 5 = 72°. In the image below you will see a five-pointed stars with vertices of 30°, one with vertices of 50° and one of vertices of 72°.
Remember to assert that the given angle is lesser or equal to 360 / n!
As shown in the image below, we notice that stars can be composed by creating n isosceles triangles, progressively rotated by a rotation angle of 180 - (180 * n - 360) / n degrees, and pinning them all in the bottom center.
Let's start by creating an isosceles_triangle function that returns an isosceles triangle rotated vertically. Keep in mind that calling triangle(160, 160, 40, STAR_COLOR) generates the following triangle.
To make it stand up straight you have to rotate it by the angle represented here below!
Hint: the pytamaro rotate function rotates a graphic counter-clockwise by the given angle. To rotate clock-wise you have to provide a negative angle!
Now you can implement the star function. Use the given STAR_COLOR color to obtain the same color that we used.
Remember that each vertex is rotated by a rotation angle of 180 - (180 * n - 360) / n from the previous one
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Star
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version c3a8286 (Mon, 14 Oct 2024 13:30:28 GMT)