At My Fingertips

Documentation

Shaded Pencil

Let's write a function that produces this pencil graphic:

pencil

You might have thought, from left to right, of the eraser, the metal ring (called the "ferrule"), the yellow body, and the (somewhat complex) point.

decomposition

Pencil Components

Let's implement the different components of a pencil, creating a function for each. We want to be able to create pencils with arbitrary body lengths and diameters, and we want to light them from the top or the bottom:

light from top or bottom

Eraser

The height of the eraser graphic corresponds to the pencil diameter. The height of the lit part of the eraser is 5/6 of the overall height. The reflex is horizontally centered within the eraser, and is offset from the vertically by the erasor's thickness. The remaining measures are computed in the eraser function.

eraser

Loading...

Ferrule

The metal ring connecting the eraser to the body of the pencil is called the ferrule. The width of the ferrule is 1/3 of the pencil diameter.

ferrule

Loading...

Body

body

To create the body, we need quite some information:

  • the pencil diameter
  • the length of the body (0 or longer)
  • the three colors
  • whether it is lit from above or below

We could define the colors inside the body function, like we did for the eraser and the ferrule, but we don't do that. We will need the same colors when creating the scalloping (the three semicircles) of the point. Thus, we define the colors somewhere else, and we pass them to our body function as an argument.

Loading...

Scalloped Point

The point consists of the wooden collar, the graphite tip, and the scalloping (the three semicircles).

scalloped point

The wooden collar is bright but has a darker part at the bottom.

This is the most challenging part of the pencil. Can you figure out a way to compose it?

Loading...

Composing the Pencil

To compose a pencil from the above components, we simply need to place the components beside each other.

If you have a beside_list function in your toolbox, you can use that. Otherwise, you can simply call beside a number of times.

Loading...

Do you like your pencil function? You may want to store it in your toolbox, so you can reuse it in other activities and in the playground!

Play

Now that we have a nice function to create pencils, play with it! Create thick and thin, and long and short pencils. Light them from the top or the bottom (rotate them, and make sure the rotated one is shaded from the top). What are realistic proportions? What proportions look the best?

Loading...

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

Shaded Pencil

Logo of PyTamaro

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

Privacy PolicyPlatform Version 1cd5229 (Tue, 05 Nov 2024 16:55:57 GMT)