Colors in Context
Due: &colors-in-context-due;
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 &grader-email;. The title of your email
should have the form &colors-in-context-subject; 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.
Background
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.
Assignment
1. Write the procedure described by the following documentation.
A couple of notes:
A "unary procedure" is a procedure that has exactly one parameter.
The value produced by the procedure should be a drawing object, as in
the drawings as values
representation of images.
;;; 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 color-name->rgb (list "red" "blue" "green")))
What does the following expression do?
(map (lambda (color) (color-in-context-drawing color rgb-complement))
primary-colors)
What does the following expression do? Why did we use
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.
Complementary. The background color
is the pseudo-complement of the foreground color.
Monochromatic: Darker. The background color
is a darker shade of the foreground color.
Monochromatic: Lighter. The background color
is a lighter shade of the foreground color.
Monochromatic: Black. The background color
is black, regardless of the foreground color.
Monochromatic: White. The background color
is white, regardless of the foreground color.
Pseudo-analogous: Redder. The background color
is slightly redder than the foreground color. (It is up to you how much
redder.)
Pseudo-analogous: Greener. The background color
is slightly greener than the foreground color.
Pseudo-analogous: Bluer. The background color
is slightly bluer than the foreground color.
Discordant. The background color is
neither complementary to, nor analogous to, nor a monochromatic variant
of the foreground color. It's up to you do decide how to combine
transformations to produce such a color.
Postscript
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.
Important Evaluation Criteria
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.
Extra credit opportunity
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.