Due: 11 a.m., Wednesday, 8 October 2008
Summary: Build a set of tools to let you visualize a set of color color schemes based on a transformation and a list of colors.
Purposes: To practice using list iteration, anonymous procedures, and color transformations. To gain experience implementing procedures as described in formal documentation.
Expected Time: Two to three hours.
Collaboration: We encourage you to work in groups of size three. You may, however, work alone or work in a group of size two or size four. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.
Submitting:
Email your answer to <weinman>. The title of your email
should have the form HW5 and
should contain your answers to all parts of the assignment. Scheme code
should be in the body of the message.
Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.
In his first guest lecture, Professor Kluber gave us some terminology for describing relationships between colors: A color scheme can be complementary, analogous, monochromatic, or discordant. Professor Kluber also encouraged us to think about how colors can look different depending on the context in which they appear.
Do we know how to compute complements, analogs, and other variants of a
color? We know some ways. In particular, we can use the basic color
transformations that were discussed in
the reading on
transforming RGB colors. For example, to compute the
pseudo-complement of a color, subject, we might use
(.
rgb-complement
subject)
In this assignment, you will use these color transformations, along with list iteration techniques and the drawings-as-values representation, to produce visualizations of colors in context.
1. Write the procedure described by the following documentation. A couple of notes:
;;; Procedure: ;;; color-in-context-drawing ;;; Parameters: ;;; subject, an RGB color ;;; transform, a unary procedure ;;; Purpose: ;;; To create a drawing where the foreground is the subject color ;;; and the background is the result of applying the given transformation ;;; to subject. ;;; Produces: ;;; drawing, a drawing object ;;; Preconditions: ;;; transform takes an RGB color as its only parameter and produces ;;; an RGB color as its result. ;;; Postconditions: ;;; drawing consists of a 50x50 square of color subject centered ;;; in front of a 100x100 square of the color resulting from applying ;;; transform to subject. ;;; The upper left hand corner of the larger square has coordinates 0,0.
2. Suppose that primary-colors is defined as follows.
(define primary-colors (map cname->rgb (list "red" "blue" "green")))
(map (lambda (color) (color-in-context-drawing color rgb-complement))
primary-colors) foreach! instead of map?
(foreach! (lambda (color) (image-show
(drawing->image
(color-in-context-drawing color rgb-complement) 100 100)))
primary-colors)
3. Write the procedure described by the following documentation. You
will need to use map or
foreach! procedure, along
with the color-in-context procedure you defined
above.
;;; Procedure: ;;; show-colors-in-context ;;; Parameters: ;;; subjects, a list of RGB colors ;;; transform, a unary procedure ;;; Purpose: ;;; To show each color in subjects in the context of the result ;;; of applying the given transformation to the color. ;;; Produces: ;;; Nothing. Called for its side-effects. ;;; Preconditions: ;;; transform takes an RGB color as a parameter and produces ;;; an RGB color as its result. ;;; Postconditions: ;;; For each color in subjects, GIMP shows a 100x100 image showing ;;; a square of that color centered on a background of the color ;;; that results from applying transform to the original color.
4. We can transform colors in a number of ways to generate interesting color schemes. Several possible transformations are described below.
Define color-list to be a list of at least five RGB colors
of your choice.
Then, write expressions using
show-colors-in-context procedure to show the colors
in your list with the transformations described below.
Note: You will create lots of images in the process of doing this problem. Remember that you can ask GIMP to close all of its images at once using the File/Close All menu item.
After completing the last problem, you may be thinking to yourself, “Isn't there an easier way to do this? What if I could write a procedure to apply lots of transformations to just a single color?” This is possible, but you don't have the tools to do it just yet. You'll see this idea in a later problem.
We will evaluate your work based on the correctness and readability of your code. Code that is exceptionally elegant, insightful, or well-crafted may earn a plus.
Observe that map can take any number of lists as its
parameters. For example,
>(map + (list 1 2 3) (list 10 20 30))(11 22 33)
Use this idea, along with drawing-hshift,
to write a new version of
show-colors-in-context that shows all of the
subject/context color squares
side-by-side in a single image, rather than each color square in a separate
image.