At My Fingertips

Documentation

Simple Diamond

Abstraction

Have a look at these geometric figures:

ABCDEF
yellowredpinkpurplecyangreen

They are all diamonds. Here are some similarities:

  • They consist of a top and a bottom part.
  • The top part consists of 5 triangles.
  • The bottom part consists of 3 triangles.
  • The diamond uses 4 different colors (brightest, bright, dark, darkest).
  • The top triangles are equilateral and all have the same size.
  • The bottom part has the overall shape of an equilateral triangle with three times the side length of the equilateral triangles in the top part.

Now let's focus on their differences, so we can figure out what parameters a diamond function should have.

def diamond(...) -> Graphic:

We can see that the colors differ, so we want to have parameters to specify the four colors.

The diamonds also differ in size, so we want to have a parameter to specify e.g., the side length of a top triangle.

def diamond(side: float, darkest: Color, dark: Color, bright: Color, brightest: Color) -> Graphic:

Implementation

Loading...

Play With Parameters

Try to create diamonds of different sizes and colors.

Loading...

Save in Toolbox

You may want to save your diamond function in your toolbox. You never know when an opportunity comes up to integrate a diamond into some more complex graphic.


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

Simple Diamond

Logo of PyTamaro

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)