At My Fingertips

Documentation

Abstraction

Have a look at these geometric figures:

ABCDE
ABCDE

We could call them rounded edges. Here are some similarities:

  • They all are horizontal.
  • They all have quarter-circle caps at the ends, rounded at the top, straight at the bottom.

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

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

def rounded_edge(...) -> 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. Different from the rounded_line function you might have implemented before, here we measure the total_length, which includes the caps.

def rounded_edge(total_length: float, thickness: float, color: Color) -> Graphic:

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

Implement

Loading...

Play With Parameters

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

Can you create a semicircle?

Does the smallest possible total_length depend on the thickness? If yes, how? You may want to add an assertion to your rounded_line function to ensure that the total_length is acceptable.

Loading...

Save in Toolbox

Save your rounded_edge function in your toolbox. It will come in handy in various ways, for example as a component of a PyTamaro iconRounded Rectangle.


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

Rounded Edge

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)