At My Fingertips
Rapid Playground
Have a look at these geometric figures:
A | B | C | D | E |
---|---|---|---|---|
We could call them rounded edges. Here are some similarities:
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.
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.
Save your rounded_edge
function in your toolbox.
It will come in handy in various ways,
for example as a component of a
Rounded Rectangle.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Rounded Edge
PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI
Privacy Policy • Platform Version 0d7866a (Fri, 20 Dec 2024 07:46:38 GMT)