Assignment 4: Creating and Testing Drawings

Due: Tuesday, September 27 by 10:30pm

Summary: In this assignment, you will experiment with different kinds of transformations of both individual drawings and lists of drawings.

Purposes: To further practice with the drawings-as-values model. To consider concise algorithms for creating images with repetitive elements. To gain further experience writing procedures.

Collaboration: You must work with your assigned partners on this assignment. You must collaborate on every problem - do not break up the work so that one person works on problem 1, another on problem 2, and another on problem 3. (The “don’t break up the work” policy applies on every assignment. This note is just a reminder.) You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.

Submitting: Email your answer to csc151-01-grader@grinnell.edu. The title of your email should have the form [CSC 151.01] Assignment 4 and should contain your answers to all parts of the assignment. Scheme code should be in the body of the message. You should not attach any images; we should be able to re-create them from your code.

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

Problem 1: Finding the Center

Topics: drawings

There are a variety of models for the “center” of a drawing. For circles and squares (and ellipses and rectangles), the model is pretty easy, the center is horizontally midway between the leftmost point and the rightmost point, and vertically midway between the topmost point and the bottommost point. But for compound shapes, we might also want to consider the relative size of the subshapes.

However, even for more complex shapes, we probably need to be able to find the center of the subshapes, and at some point, everything breaks down into a circle or a square (or an ellipse or rectangle).

a. Write a procedure, (simple-center-x drawing), that finds the x coordinate of the center of a drawing using the simple metric of “horizontally midway between the leftmost point and the rightmost point”.

b. Write a procedure, (simple-center-y drawing) that finds the y coordinate of the center of a drawing using the simple metric of “vertically midway between the topmost point and the bottommost point”.

Problem 2: Testing Your Procedures

Topics: testing

Write a test suite for simple-center-x and simple-center-y.

You should make sure to conduct all of the following tests.

  • The center is at the origin.
  • The center is along the x axis.
  • The center is along the y axis.
  • The center is in quadrant I (and II and III and IV).
  • Circles, squares, ellipses, rectangles, and compound drawings.
  • Relatively small drawings.
  • Relatively large drawings.
  • Drawings whose center coordinates are integers.
  • Drawings whose center coordinates are not integers.
  • Anything else you think is applicable.

Problem 3: Drawing Circles

Topics: lists of drawings

In the lab on lists of drawings, you observed that we could create interesting patterns by making a list of a simple shape and two lists of horizontal and vertical offsets, and then combining it all with appropriate calls to map.

Let’s suppose we want to take some simple shape and make a circle from 36 copies of that shape. Here’s the start of a program to do just that.

(define circle-of-drawings
  (lambda (drawing)
    (map vshift-drawing 
         (map circle-ycoord (iota 36))
         (map hshift-drawing
              (map circle-xcoord (iota 36))
              (make-list 36 drawing)))))

Here’s a sample use of that procedure.

> (define c5 (scale-drawing 5 drawing-unit-circle))
> (image-show (drawing->image (drawing-compose (circle-of-drawings c5)) 200 200))

Circle of circles

As you may have noted, circle-of-drawings requires two procedures, circle-xcoord and circle-ycoord, that each take an integer between 0 and 35, inclusive, as a parameter and return the x or y coordinate of that copy of the drawing in the circle.

Write circle-xcoord and circle-ycoord. You will likely need to use sin and cos, which each take as input angles in radians.

Problem 4: Compound Drawings

Topics: lists of drawings

You now know a variety of techniques for manipulating drawings and lists of drawings. Write a procedure that creates interesting drawings. You may choose what to name your procedure and what inputs it takes, provided you have at least one input. You must use map at least once in your procedure (or one of its helpers) and you must programatically change colors of the drawings you use.