At My Fingertips

Documentation

Abstraction

Have a look at these geometric figures:

ABCDE
ABCDE

They are all rounded lines. Here are some similarities:

  • They all are horizontal.
  • They all have rounded (semicircular) caps at the ends.

You might argue that figure C, the yellow circle, is hardly a rounded line. Hold that thought!

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

def rounded_line(...) -> Graphic:

We can see that the color differs, so we want to have a parameter to specify the color.

Besides the color, there's also the length and thickness.

We need to decide how we measure the length. Let's measure it without the caps. We use the parameter name core_length to describe that.

def rounded_line(core_length: float, thickness: float, color: Color) -> Graphic:

Note that the line's thickness determines the radius of the semicircular caps.

Implement

Loading...

Play With Parameters

Play with your rounded_line function, creating lines with different sizes and colors.

Can you create a circle?

Loading...

Save in Toolbox

Save your rounded_line function in your toolbox. It should come in handy in the future.


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

Rounded Line

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 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)