At My Fingertips

Documentation

In this activity you will build the Swiss flag:

swiss flag

The goal of this exercise is to build the flag in a compositional way: you start with some primitives (e.g., rectangles), and you compose them into more complex graphics until you end up with the complete flag.

Background

We can start by creating the red square that acts as a background:

Loading...

Cross

To create the cross, we start by creating its horizontal arm. Then we create the vertical arm by creating a rotated version of its horizontal arm (call rotate with an angle of 90 degrees). By overlaying the two arms on their centers we build the cross:

Loading...

Flag

Finally, we can compose together the cross and the red background keeping the former in the foreground:

Loading...

And... we are ready to show the flag!

Loading...

What You Learned

You built the Swiss flag compositionally. You split the original "big" problem, the whole flag, into two subproblems: the red background and the white cross. You further broke down the subproblem of creating the white cross into two smaller subproblems: creating the horizontal and vertical arms.

Decomposing a problem into subproblems helps to reason and solve these subproblems independently. You can then combine the solutions of the subproblems to obtain the solution of the "bigger" problem.

This is a small example, but it is very instructive of an important principle in informatics!


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

Swiss Flag

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)