At My Fingertips

Documentation

Looped Square

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.

looped square

Decomposition

To help us to decompose the sign, let's overlay it with a grid:

with 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.

3

Corner Loops Made of Drops

The sign contains four loops at the corners of a square. Let's write code to create one of those corner loops:

loop

This loop can be seen as the overlay of a smaller white "drop" over a larger black "drop":

drops

Loading...
Loading...

Looped Square

The entire size (e.g., width) of the sign is made up of three equally-width gaps and four equal-width lines.

guide

Loading...

What You Learned

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

Logo of PyTamaro

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

Privacy PolicyPlatform Version e1c4550 (Sun, 23 Feb 2025 15:42:54 GMT)