CSC151.01 2009F Functional Problem Solving : Labs

Laboratory: Drawing Smiley Faces

Summary: In this laboratory, you will begin to study algorithms as you explore various techniques for describing images.


As you will learn throughout the semester (and will be told the first day of class), one of the primary activities computer scientists do is to write clear and unambiguous instructions for a variety of tasks. In writing these instructions, it is essential that you understand what the device or person for which you are writing instructions knows.

To get you accustomed to writing instructions, we'll start with a simple task. Your goal is to teach me how to draw a traditional yellow smiley face on the white board. (If you don't know what a Smiley Face looks like, there's a good example at

To make it a bit more interesting, different groups will be limited to different sets of basic operations with which to give instructions.


When you entered the room (or soon thereafter), you received a colored sticker with a smiley face on it. Find two other people with the same color sticker and sit together. If we don't have an exact multiple of three in the class, feel free to form groups of four or two, as necessary. If you are color blind, color deficient, or otherwise unable to determine the color of your sticker, please ask a neighbor to identify the color on your sticker and to help you find someone with the same color sticker.

Once you have formed a group, read through all of the variations below and then do the work assigned to your group.


Orange Groups: Simple Motions

Write instructions for drawing a smiley face.

In writing these instructions, your goal should be to describe the physical actions I need to take in order to draw the face.

In those instructions, you should assume that I have never previously encountered pens, whiteboards, or the like. You should also note that I have never heard of shapes, so you may not refer to things like circles or squares.

You will note that other groups can assume that I know about the Cartesian plane. You may not.

Yellow Groups: Circles, Circles, and More Circles

Write instructions for drawing a smiley face.

In those instructions, you should assume that I only know how to draw filled-in circles, but that you can choose the color and position of the circles I draw. (I can also draw white circles, which, in effect, erases anything beneath them.) You may also assume that I know coordinates on the Cartesian plane. I draw only in opaque ink.

In other words, the only instructions you can give me are of the form: “Draw a color circle of radius R centered at X,Y.” You can, however, tell me to draw a lot of circles.

Green Groups: Drawing Through Dots

Write instructions for drawing a smiley face.

In those instructions, you should assume that I have been so corrupted by the Impressionists that the primary thing I know how to do is draw a dot on the board in a specified color at a specified location.

Because it can be difficult to describe each dot individually, you may also assume that I can figure out sets of dots that meet particular criteria, so that you can give instructions like “put orange dots at all positions in which the sum of the x and the y coordinates is 10” or “put green dots in all positions in which the product of the x and the y coordinates is less than 20”. Note that I can only put dots at positions in which the x and y coordinates are whole numbers, and that dots fill a region of one unit.

You may also assume that I can can compute functions, so that you can write things like “put violet dots for at (x,x^2-5) for all x between 1 and 20”.

Blue Groups: Drawing with Robotic Turtles

Write instructions for drawing a smiley face.

In those instructions, you should assume that I am trying to draw the face on the whiteboard, that I always have a direction in which I am moving the pen, and that I am limited in my actions to:

  • selecting a color of pen;
  • making sure that the tip of the current pen is in contact with the board;
  • lifting the pen off the board;
  • moving forward a specified distance;
  • changing my direction of motion left or right by a specified angle;
  • repeating any combination of actions some number of times; and
  • repeating any combination of actions until some condition is reached.

For example, to have me draw the outline of a blue square of edge length one foot, you might tell me to

  • select a blue pen
  • make sure the tip of the pen is in contact with the board
  • repeat four times
    • move forward one foot
    • turn right 90 degrees

This technique for drawing mimics one of the more popular ways to teach robots how to draw, and is called turtle graphics. (In turtle graphics, the turtles draw on the floor, rather than the board, but the basic actions are essentially the same.)

You may assume that I start at the center of the area in which I plan to draw, and that the direction is up.


  • Before going through this exercise, which group would you have preferred to be in? Why?
  • After going through this exercise, which group would you have preferred to be in? Why?
  • How did the kinds of instructions the different groups gave differ?
  • What lessons can you derive about writing algorithms from this exercise?

Creative Commons License

Samuel A. Rebelsky,

Copyright (c) 2007-9 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)

This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.