Programming Languages (CS302 2007S)

Homework 4: Representing Images, Revisited

Assigned: Friday, February 9, 2007
Due: Friday, February 16, 2007
No extensions!

This homework is also available in PDF.

Summary: In this assignment, you will expand upon the ideas from the reading on representing images.

Purposes: To give you more experience understanding thinking about how we might represent images and about the relevance of the functional paradigm to that representation.

Expected Time: Two to three hours.

Collaboration: You may work alone or you may work in a group of size two or three. I encourage you to work in groups on this assignment. You may discuss the assignment with anyone you'd like, provided you cite such discussions in your assignment.

Submitting: Email me your answer. More details below.

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

Assignment

In the reading on representing images, you experienced a simple representation of drawings as lists of lists of points. While that representation provides an appropriate environment for exploring basic issues (particularly issues of higher-order programming), it is a bit limited as a way of representing images. In particular, it ignores some things that a designer might find useful, such as associating a line size or a color with each drawing. In addition, one might want to provide additional facilities, such as rotation.

A New Representation of Drawings

Consider the following definition of drawings.

A drawing is either (1) a four element list consisting of (a) the symbol
drawing, (b) a color, (c) a pen, and (d) a list of points;
or (2) a list of drawings.

Create the following procedures for working with drawings:

(primitive-drawing color pen pt1 pt2 ... ptn)
Create the basic kind of drawing.
(combine-drawings drawing1 drawing2 ... drawingn)
Create the compsite kind of drawing.
(render img drawing)
Render the drawing on the specified image. For a compound drawing, you'll need to recurse on the subdrawings. For the basic drawing, you'll need to set the pen and color, and then connect the points.
(translate drawing delta-x delta-y)
Create a copy of the drawing, translated the specified amount.
(scale drawing scale-x scale-y)
Create a copy of the drawing, scaled by specified amount.
(recolor color drawing)
Change the color of the drawing (including any subdrawings) to the specified color.

Part Two: Rotation

Write a procedure, (rotate angle drawing), that rotates the given drawing about the origin.

Important Evaluation Criteria

Correct, working, solutions will earn a check.

Particularly elegant solutions that take advantage of higher-order principles and that show evidence of refactoring are likely to receive a higher grade.

Non-working or incorrect solutions will earn a lower grade.

Submitting Your Homework

Please submit this via email, using a title of CSC302 HW4.

Attach the files that you've created to that email message.

 

History

Thursday, 8 February 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 Sun Apr 29 11:25:31 2007.
The source to the document was last modified on Thu Feb 8 21:04:24 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2007S/Homework/hw.04.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu