At My Fingertips
Rapid Playground
Have a look at these geometric figures:
A | B | C | D | E |
---|---|---|---|---|
Here are some similarities:
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:
points
outer_radius
(radius of the circumscribed circle, distance from center to point)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.
Play with your star
function, creating stars with different radii, numbers of points, and colors.
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 c08406b (Wed, 20 Nov 2024 12:30:00 GMT)