At My Fingertips

Rapid Playground

Documentation

Eyes

In this activity you will write a function that composes multiple graphics.

Decompose this Graphic

eyes

If you said "a pair of eyes", that's a good start! But could you be more precise? Maybe "a pair of eyes, one beside the other"? Sounds good! Now it's clear we're not talking about some weird monster, with one eye above the other. But could you go into a bit more detail? What is an eye made of? You might want to describe it as follows: "An eye is composed of two concentric circles, a small black circle overlayed on a large white one." We could be even more precise ("small"? "large"?), but let's use Python instead of English for a 100% precise definition of our graphic.

Circles

Our graphic is mostly composed of circles. You already should have a function that creates a circles:

def circle(diameter: float, color: Color) -> Graphic

If you don't have one in your toolbox, do the PyTamaro iconSimple Snowman activity to learn how to store a circle function in your toolbox.

Then import circle from your toolbox:

Loading...

Now let's check whether the function creates decent circles:

Loading...

An Eye

Since we are going to need two eyes, let's implement an eye function to avoid having to write the same code twice. The pupil's diameter should be half of the eye's diameter. The sclera (the bigger circle) should be white, and the pupil should be black.

Loading...

The white circle might be a bit hard to see. If you hover over the eye, the background behind your graphic will turn into a checkerboard pattern. This way you should more clearly see the eye.

Two Eyes

You can now implement the eyes function that returns a graphic that consists of two eyes beside each other. Use the eye function you just implemented!

Loading...

What You Learned

You practiced problem decomposition: You decomposed a graphic into its pieces. This means that you decomposed the problem. Then you implemented functions to create the pieces and compose them into the overall graphic.

You imported the circle function from your toolbox, and the overlay and beside functions from the PyTamaro libray, and you implemented two new functions right here: eye and eyes.


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

Eyes

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version 9af3915 (Tue, 07 May 2024 08:10:35 GMT)