# Assignment 3: Algorithmically Creating Simple Images

Due: 9:00 a.m., Wednesday, 6 February 2008

Summary: In this assignment, you will explore the three models of images we've learned so far (GIMP tools, turtles, and drawings as values) as you consider how to create some simple images.

Purposes: To give you some experience writing algorithms in Scheme. To encourage you to think about the strengths and weaknesses of the different representations.

Expected Time: Two to three hours. You should stop when you reach three hours! If you cannot complete the assignment in that time, note that on your solution and you'll get at least a check.

Collaboration: We 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”).

Submitting: Send your answer to . The title of your email should have the form `CSC151.01 2008S Assignment 3: Simple Images` 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.

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

## Preliminaries

We've now seen a variety of ways to describe images, both informal and formal. We've even seen three Scheme-based models: GIMP tools, turtle graphics, and drawings as images.

Given an image to construct, how do you choose which one to use? As you noted in the previous assignment, in many cases, one model will lend itself to the problem more naturally than another. For example, if you needed a lot of diagonal lines in your image, you would be unlikely to use the drawings as values model, since it does not directly support lines.

But one might also look at the algorithms (programs) that get constructed under a particular model. Computer scientists compare algorithms in many different ways, and we could use some of the common comparisons to compare the resulting algorithms. For example, we might strive to find the algorithm that is fastest or that is most concise. Since speed of algorithms can be difficult to measure, for this assignment, we will focus on concision.

How will we measure concision? One could count characters, but that would encourage programmers to use unreadable, one-letter, names. A better way is to count the number of units of expression (other than parenthesis). For example, `+`, `body`, `really-thin-left-arm`, and `3.14159` are each considered a single unit in analyzing conciseness. We'll use that metric in looking at solutions in this assignment.

Note that concision should not require you to sacrifice readability. Since we are not counting characters, you should use clear names, such as `stick-body`, rather than shorthand, such as `s`. Note also that this metric does not penalize you for using whitespace: spaces, tabs, newlines, and blank lines. Please use as much whitespace as is necessary to make the code readable.

## Assignment

Consider the following three images. For each image, write a program to generate the image, using either the Scheme-based GIMP tools, turtle graphics, or drawings. Your goals are to correctly generate the image and to make your program for generating the image as concise as possible. (Reminder: In considering conciseness, we care more about units of expression, rather than number of characters.)

Since choosing the right representation is likely to contribute to the conciseness of the code, make sure that you understand the representations well. You may find it particularly helpful to read the “For those with extra time” section of the reading on drawings as values.

• a. A stick figure. That is, a circle with a long vertical line trailing down from it (representing the body), and four appropriately drawn angled lines sticking out from the body.
• b. A star of David. That is, a six-pointed star, typically drawn with six lines.
• c. A checkerboard. That is, an 8x8 grid of squares in alternating black and red colors.

Note that you may only use one of the models for each image, but you may use different models for the different images.

## Important Evaluation Criteria

The first criterion we will use in evaluating your assignments is correctness. In particular, we will check to ensure that each program generates the appropriate image.

The second criterion we will use in evaluating your assignments is conciseness. That is, we will look to see whether your program is short or long for the problem. We will not differentiate short and long variable names, so please use comprehensible names.

We will also consider your choice of model, the creativity you express in making the images, and a host of other issues.

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-8 Janet Davis, Matthew Kluber, and Samuel A. Rebelsky. (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 `http://creativecommons.org/licenses/by-nc/2.5/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.