At My Fingertips
Rapid Playground
Let's create a function that can produce popsicles like these:
We could say it is a watermelon popsicle, but that's not really describing the composition.
How about:
The popsicle is symmetric. It has width w, and an overall height 3w.
The ice has a total height of 2w and is as wide as the overall popsicle. The radius of the top edge of the ice is w/4.
The stick has total height w and a width w/4. The semicircle at the bottom of the stick has radius w/8.
To create the ice, we want to have a rounded edge.
If you do not yet have a rounded_edge
function in your toolbox,
solve the Rounded Edge activity
to create one.
Then import your rounded_edge
function from your toolbox.
Note: We defined the stick_color
as a constant inside the function.
Any popsicle created by this function will have a stick in that same color,
and nobody outside that function needs to know about that color.
The ice_color
, though, is a parameter:
we want to create different kinds of popsicles,
with differently colored (and tasting) ice!
Try to create popsicles in different sizes and colors. Try the given lime color. Can you create a realistically looking orange? A chocolate brown?
If you like your simple_popsicle
function, save it in your toolbox.
This activity has been created by LuCE Research Lab and is licensed under CC BY-SA 4.0.
Simple Popsicle
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)