CSC151.02 2010S Functional Problem Solving : Assignments

Assignment 2: Algorithms for Drawing

Due: 10:00 a.m., Wednesday, 3 February 2010

Summary: In this assignment, you will think about ways to write algorithms for creating drawings.

Purposes: To give you more experience thinking about writing algorithms. To give you the opportunity to identify parts of an algorithm.

Expected Time: Two to three hours. After two-and-a-half hours, stop what you're doing, write up what you've accomplished so far (which should take you less than half an hour) and write at the top of your assignment “I spent nearly three hours on this assignment. There's more to life than computer science!” Doing so will earn you at least a check on this assignment. You should also visit with me to discuss the stumbling blocks you seem to have encountered.

Collaboration: I would prefer that you work in groups of size three. However, you may work alone, in a group of size two, or a group of size four. You may discuss this assignment and possible solutions with anyone you wish. If you discuss this assignment with people other than group members, make sure to include a citation (e.g., “I consulted this person, who helped me do this”).

I will check at the beginning of the next class to ensure that everyone who wants a group has a group.

Submitting: Send your answer to . The title of your email should have the form Assignment 2: Algorithms for Drawing, Revisited and should contain your answers to all parts of the assignment. I prefer that you put your answers in the body of the message, rather than as an attachment.

Notice: So that this assignment is a learning experience for everyone, I may spend class time publicly critiquing your work.


We've started to learn a variety of techniques for writing algorithms. We can use a formalized version of English or we may use a language like Scheme. English has the advantage of being a bit easier to write (at least right now) while Scheme has the advantage of being less ambiguous. Still, our central goal is to write algorithms.

What kinds of things might one consider in assessing the various solutions? One might reflect on the correctness and complexity of each algorithm. One might look at the use of various algorithm components (repetition, conditionals, naming, subroutines, etc.) One might compare the different core operations. One might also look at the quality of the result that is produced. Finally, one might consider how easy it is to understand the algorithm.


Part One: Describing a Drawing

Your first task is to give an algorithm (in English) for creating a drawing of some recognizable object or scene. The choice of subject is up to you. However, you are limited to the following “operations” in creating your drawing:

  • Outline a rectangle with a specified size, location, color, and “brush
  • Draw a filled rectangle with a specified size, location, and color.
  • Outline an ellipse with a specified size, location, color, and “brush
  • Draw a filled ellipse with a specified size, location, and color.
  • Draw a line segment with specified endpoint locations, color, and “brush

Your drawing algorithm should use at least ten of these operations, and use at least one of each shape (rectangle, ellipse, and line), and at least one of each type of shape (filled or outlined).

Note: If you with to use a Linux-based MathLAN computer to write your instructions, here is how to launch a simple text editor:

  • Click on the menu in the lower-left corner of the control panel.
  • Click on "Accessories" (at the top)
  • Move the mouse to the bottom of the pop-up menu that appears where there is an arrow pointing downward.
  • Click on Text Editor. (Note: There is also a "TextEdit" entry. That is not what you want.)

This will open the gEdit text editor, which has a more or less intuitive interface.

gEdit is not your only option. You might also consider using your Web-based email program to compose the instructions (just save regularly) or Google Docs. You can even write the instructions in MediaScript (just don't click Run).

Part Two: Giving GIMP Instructions

In an upcoming lab, you will learn how to give the GIMP precise instructions in MediaScheme to create drawings using operations much like the ones you would use to draw in the GIMP (e.g., choosing colors and brushes, selecting regions, stroking and filling). Translate your algorithm above into precise commands using the GIMP tools for Scheme.

To help keep us oriented, please place comments in your code to explain at a higher level what the instructions do. Any line that begins with a semicolon is ignored by the Scheme interpreter, but can be read by humans as a comment. For example, you might precede sections of code with comments such as the following:

; Draw a red square
(context-set-fgcolor! "red")
(image-select-rectangle! canvas REPLACE 10 10 40 30)
(image-fill-selection! canvas)

or even

; Draw the left eye
(image-select-ellipse! ...)

Part Three: Reflecting on Changes

Did you have to modify your algorithm at all to actually create your image using GIMP? If so, describe what things needed to be changed. If not, what about your approach to part one made it possible to move to part two with ease? Could you automate the translation of algorithm from the first form to the second?

Important Evaluation Criteria

The first criterion we will use in evaluating your assignments is correctness - is each set of instructions likely to produce the desired image?

The second criterion we will use in evaluating your assignments is clarity - how easy is it to understand your instructions and your intentions?

The third criterion we will consider is creativity. We will consider whether you have used innovative or particularly interesting techniques to create a drawing. We will also consider the creativity of the drawing, itself.

Creative Commons License

Samuel A. Rebelsky,

Copyright (c) 2007-10 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.