At My Fingertips

Documentation

Abstraction

Have a look at these geometric figures:

ABCDE
5345image-5.png

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.

Decomposition

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

16 points

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

16 points, 2 colors

Kite

We need a function to create kites, like this:

kite(100, 70, 45, my_color)

The above call will produce the following kite:

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 PyTamaro iconkite activity. If not, please go there to implement that function now and to add it to your toolbox.

Loading...

Star

Loading...

Play With Parameters

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 in Toolbox

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

Logo of PyTamaro

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

Privacy PolicyPlatform Version c08406b (Wed, 20 Nov 2024 12:30:00 GMT)