At My Fingertips

Rapid Playground

Documentation

Ghosts

In this activity you will implement the ghost function to create a ghost graphic

ghosts

The Colors

In the official Pac-Man game there are four ghosts. They have names!

  • Inky
  • Blinky
  • Pinky
  • Clyde

Let's define constants holding the colors of the ghosts:

Loading...

The ghost function

Decomposition

Observe the image below to understand how to decompose a ghost into basic shapes.

ghost

Parameters

We want to implement the ghost function so that it can generate ghosts of different sizes and colors.

Since we want to be able to choose the size and the color of the ghost, those are the values to be parameterized. Therefore, the function should have a parameter that models the size of the ghost (which could be something like width, head_radius, ...), whose type should be float, and a parameter that models the color of the ghost, whose type should be PyTamaro iconColor.

Implementation

Now let's implement a function that produces a ghost, given the wanted width and color.

But don't cram all the code into this one function: when needed, introduce addtional functions, each producing a component of the ghost.

The code should be readable and without code duplicates!

If you have useful functions in your toolbox (e.g. equilateral_triangle, semicircle, ...) you can import them and use them here!

Loading...

What You Learned

In this activity you practiced problem decomposition by decomposing the ghost graphic into simpler graphics, and the ghost function into simpler helper functions. You also used user-defined colors, created with PyTamaro iconrgb_color.

Most importantly, you had a chance to learn about the choice of parameters for a function, and what types the parameters should have.

You might also have imported some useful functions from your toolbox (like semicircle or equilateral_triangle).


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

Ghosts

Logo of PyTamaro

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

Privacy PolicyPlatform Version f81ff6d (Thu, 02 May 2024 16:52:36 GMT)