Homework 15: Higher-Order Graphics

Assigned: Friday, April 13, 2007
Due: Tuesday, April 17, 2007

Summary: Build new procedures for interesting manipulations of line drawings.

Purposes: To further experiment with map and other higher-order procedures. To consider a new design pattern.

Expected Time: One to three hours.

Collaboration: You may work in a group of any size between two and four, inclusive. You may consult others outside your group, provided you cite those others. You need only submit one assignment per group.

Submitting: Email me your work, using a subject of CSC151 Homework 15.

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


Assignment

In this assignment, you'll be building on the reading and lab on line drawings.

1. Scaling figures

Write a procedure, (superimpose figure sizes), as follows. An elegant implementation will make use of the map procedure.

;;; Procedure:
;;; superimpose
;;; Parameters:
;;; figure, a list of points
;;; sizes, a list of integers
;;; Purpose:
;;; Make a new drawing consisting of the figure scaled to several different sizes.
;;; Produces:
;;; drawing, a list of lists of points
;;; Preconditions:
;;; None
;;; Postconditions:
;;; (length drawing) equals (length sizes)
;;; (list-ref drawing i) is equal to (scale-points (list-ref sizes i) (list-ref sizes i) figure)

2. The zero? procedure

Script-Fu unfortunately does not implement the zero? procedure from DrScheme.  Write your own implementation of zero? that makes use of the = and left-section procedures.

3. Jittering figures

We might also like to jitter a figure: that is, make several copies of the same figure that all have been randomly varied with the same maximum variance. Here's a way to make three varied copies of the tree figure:

(define jittered-tree (list (vary-points 5 tree) (vary-points 5 tree) (vary-points 5 tree)))

But you can see it would get very tedious to do this if we wanted more than just a few copies.

Write and document a procedure, (jitter times amt-to-vary figure), that makes a list containing times copies of figure, each copy varied by amt-to-vary. (You may want to use the zero? procedure that you wrote in the exercise above.)

To test out your procedure in Script-Fu, you might try the following sequence of commands.

(define tree (list (point 15 30) (point 18 14) (point 5 18) (point 8 8) (point 20 0) 
(point 30 2) (point 35 19) (point 23 16) (point 23 30)))
(define img (create-image 100 100))
(show-image img)
(draw img (jitter 3 5 tree))

4. Thinking about patterns

Your procedure, (jitter times amt-to-vary figure), should look fairly similar to the (roll-dice n) procedure from the lab on randomness and simulation

Write a general pattern for this style of procedure, similar to the pattern for recursion over lists or the pattern for checking list types given in the reading on representing line drawings.

Can we write a procedure that encodes this pattern, similar to the map procedure?  How can we do it, or why can't we?


Janet Davis (davisjan@cs.grinnell.edu)

Created April 12, 2007
Last revised
April 14, 2007