# Assignment 2: Drawing Circles, Revisited

Due: 4:00 p.m., Tuesday, 4 September 2007
Free extension of one day!

This homework is also available in PDF.

Summary: In this assignment, you will extend your work from the introductory lab on writing algorithms.

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

Expected Time: One to two hours.

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).

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

Contents:

## Background

In the first laboratory for this course, I asked various groups to consider mechanisms for drawing smiley faces. Given the limits of class time, we were not able to consider every mechanism. We were able to see two aproaches to drawing with circles, and a combined approach by two groups of drawing with pixels.

What kinds of things might we consider in assessing the various tasks? We might reflect on the accuracy and complexity of each algorithm. We might look at the use of various algorithm components (repetition, conditionals, naming, subroutines, etc.) We might compare the different core operations.

## Assignment

### Part One: Drawing Through Dots, Revisited

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 canvas in a specified color at a specified location.

I will be drawing the smiley face on a canvas 101 millimeters by 101 millimeters. The tip of my paintbrush is about one millimeter by one millimeter. To simplify your descriptions, I have broken down the canvas into a grid of size 100x100. In referring to a point on the grid, you need to tell me the row and column. We will start numbering with row 0 (the top row) and column 0 (the leftmost column). In referring to rows and columns, you may only use whole numbers.

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 row number and the column number is 10 or put green dots in all positions in which the product of the row number and column number is less than 20.

You may also assume that I can can compute functions, so that you can write things like for all integers, c, between 1 and 20, put a violet dot in the grid point whose column is c and whose row number is c*c+5.

### Part Two: Drawing with Robotic Turtles

Write instructions for drawing a smiley face in a square that is 101 millimeters by 101 millimeters.

In those instructions, you should assume 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 floor;
• lifting the pen off the floor;
• moving forward a specified distance;
• turning left or right by a certain 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 floor
• 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.

You may assume that I start at the center of the area in which I plan to draw, and that I am facing North.

### Part Three: Comparing Types of Drawing

You have now seen three sets of rules for describing drawings - The circle-based drawings we did in class, the grid-of-dots drawings you did in part one, and the turtle drawings you just did in part two.

a. Which was the easiest set of rules in which to draw a smiley face? Why?

b. If you had to draw a simple picture of a house, which would you prefer? Why?

c. If you had to draw a stick figure, which would you prefer? Why?

## Important Evaluation Criteria

The first criterion I will use in evaluating your assignments is correctness - is each set of instructions likely to produce the desired image. As I consider correctness, I will also check to see whether you have avoided ambiguous instructions and how easy it is for me to misinterpret those instruction.

The second criterion I will use is creativity. I wil consider whether you have used innovative or particularly interesting techniques for giving instructions or analyzing the choices in part three.

Please submit this work via email. The email should be titled CSC151.02 Assignment 2 and should contain your answers to all parts of this assignment.

Please send your work as the body of an email message. I don't like attachments, and prefer not to receive them when they can be avoided.

## History

Late August, 2007 [Samuel A. Rebelsky]

• Designed.

Saturday, 1 September 2007 [Samuel A. Rebelsky]

• Created.
• Released.

Monday, 3 September 2007 [Samuel A. Rebelsky]

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Mon Dec 3 09:55:50 2007.
The source to the document was last modified on Mon Sep 10 20:50:00 2007.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007F/Assignments/assignment.02.html`.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2007 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.