At My Fingertips

Rapid Playground

Have a look at these geometric figures:

A | B | C | D | E |
---|---|---|---|---|

Here are some similarities:

- All figures are stars
- In a given figure, all sides have the same length
- In a given figure, the angles in each point are the same

You may also notice that they are rotated such that one of their points points straight up.

`def star(...) -> Graphic:`

We can see that the color differs,
so we want to have a parameter to specify the `color`

.

There are different approaches to unambiguously specify the shape. Here is one possible way:

- the number of
`points`

- the
`outer_radius`

(radius of the circumscribed circle, distance from center to point) - the
`inner_radius`

(radius of the indented points, distance from center to indentation)

There would be other ways (e.g, to specify angles, the side lengths),
but let's go with `points`

, `outer_radius`

, and `inner_radius`

.
The following function signature reflects this choice:

`def star(outer_radius: float, inner_radius: float, points: int, color: Color) -> Graphic:`

Note that the parameter `points`

has type `int`

:
the number of points has to be an integer number.
We can't have a star with, say, 2.5 points.

How would you decompose a star, given that you have the PyTamaro functions and the functions in your own toolbox?

One way to achieve this is to decompose the star into a number of kites, one kite per point:

We need a function to create kites, like this:

`kite(100, 70, 45, my_color)`

The above call will produce the following kite:

The first argument is the length of the symmetry diagonal (vertical), the second argument specifies the length of the bottom sides (starting at the bottom tip), and the third argument specifies the angle between the bottom sides (at the bottom tip).

You already should have created a `kite`

function in the kite activity. If not, please go there to implement that function now and to add it to your toolbox.

Loading...

Loading...

Play with your `star`

function, creating stars with different radii, numbers of points, and colors.

Loading...

A star with a single point consists of a single kite with an angle of 360 degrees. That kite is composed of two triangles, each of them has a height (and thus an area) of 0. The area of the entire star is 0, which means it's impossible to save it in an image file. Image files cannot be 0 pixels by 0 pixels big (image file format designers were not mathematicians; they don't consider 0 a perfectly fine size).

A star with two points corresponds to a rhombus.

Yes, using the same value for both radii produces a regular polygon with an even number of sides (twice the number of points).

Save the `star`

function in your toolbox.
It can be useful in the future.

This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.

Radius-Based Star

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

Privacy Policy • Platform Version 79aacf0 (Fri, 08 Nov 2024 13:24:29 GMT)