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

*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

As shown in the image below, we notice that stars can be composed by creating * n isosceles triangles*, progressively rotated by a

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!

Loading...

Now you can implement the **star** function. Use the given STAR_COLOR color to obtain the same color that we used.

- parameter
is the number of vertices of the star, assert that it's at least 3**n** - parameter
is approximately the size of each vertex, assert that it's a positive number**size** - parameter
is the angle that each of the vertices should have, assert that it's bigger than 0 and it's less than**angle****360 / n**

Remember that each vertex is rotated by a **rotation angle** of **180 - (180 * n - 360) / n** from the previous one

Loading...

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)