At My Fingertips
Rapid Playground
The "looped square" is a symbol you may know from the Apple keyboard's Command key. It is also known as the "place of interest" sign in Nordic countries.
To help us to decompose the sign, let's overlay it with a grid:
We want to develop the following function:
def looped_square(size: float, line_width: float, line_color: Color, background_color: Color) -> Graphic:
The function allows us to specify not just the overall size (width, height) of the sign, but also its line width. Moreover, we can specify the color of the line, and the color of the background.
The sign contains four loops at the corners of a square. Let's write code to create one of those corner loops:
This loop can be seen as the overlay of a smaller white "drop" over a larger black "drop":
The entire size (e.g., width) of the sign is made up of three equally-width gaps and four equal-width lines.
You practiced decomposition by breaking down the problem into multiple functions. You also practiced abstraction, because the functions have parameters and thus a function can produce an entire family of similar graphics.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Looped Square
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version e1c4550 (Sun, 23 Feb 2025 15:42:54 GMT)