&blending-colors-prefix;Blending Colors
Due: &blending-colors-due;
Summary: In this assignment, you will use the
color manipulation operations you learned in the lab on RGB colors to
blend colors together.
Purposes: To get you comfortable working with
the basic color operations in the GIMP. To help you think more
about colors.
Expected Time:
Two to three hours.
Collaboration: You must work
in a group of size two or size three. (If you need help identifying
a group, please let me know.) You may discuss this assignment and
possible solutions with anyone you wish. If you discuss this assignment
with people other than group members, make sure to include a citation
(e.g., I consulted this person, who helped
me do this
).
Submitting:
Email your answer to &grader-email;. The title of your email
should have the form &blending-colors-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
A common effect in digital graphics is a color blend, in which colors
range more or less smoothly from one color to another. For example,
the following image shows a blend from blue to red. Isn't it beautiful?
What tools does one need to construct blends like the above? You must
know how to manipulate the red, green, and blue components of colors
used in digital images. And you know how to do that. In particular,
you can extract the red, green, and blue components of a color using
rgb-red,
rgb-green, and
rgb-blue, and you can construct an RGB color
using rgb-new.
Along with basic mathematical operations and the
image-set-pixel! operation, this is enough to let you
construct small color blends.
Assignment
a. Write and document a procedure, (rgb-average
color1 color2) that
takes two RGB colors as parameters
and computes the average of those two colors.
That is, the procedure should produce a new RGB color where
the red component is
the average of the red components of the two colors,
the green component is the average of the
green components of the two colors, and the blue component is
the average of the blue components of the two colors.
You should document the rgb-average procedure using
the 6 P's.
b. Consider the following procedures that build an image for a
five-pixel blend. You should test the procedure with a few pairs of
colors, such as blue and red, green and yellow, and darksalmon
and lightsalmon. (You will need to use
color-name->rgb to convert color names into the
corresponding RGB colors.)
i. Explain why you think image-five-pixel-blend
uses a helper procedure.
ii. Explain why you think image-five-pixel-blend-helper ends with fivebyone.
c. Write and document a procedure,
(rgb-weighted-average
weight
color1
color2),
that takes a weight between 0 and 1 and two RGB colors, and computes
the RGB color made up of weight parts
of color1 and
(- 1 weight) parts of
color2.
It is easiest to think about this procedure in terms of particular
components. Suppose the red component of color1
is 0 and the red component of color2 is 120.
If weight is 0.2, then the red component of
the weighted average will be
96 (that is, 0.2*0 + 0.8*120). If
weight is 0.75, then the red component
of the weighted average will be 30 (that is, 0.75*0 + 0.25*120).
For another example,
suppose the green component of color1
is 200 and the green component of color2 is
0. If weight is 0.2, then the green component
of the weighted average will be 40 (that is 0.2*200 + 0.8*0).
Similarly, if weight is 0.75, then the
green component of the weighted average will be
150 (that is 0.75*200 + 0.25*0).
What if the components are both non-zero? Suppose the blue
component of color1 is 120 and the
blue component of color2 is 180.
If weight is 0.2, then the green component
of the weighted average will be 168 (0.2*120+0.8*180 =
24+144). If weight is
0.75, then the green component of the weighted average will
be 135 (you can do the math).
d. Write a
procedure,
(image-11-pixel-blend
startcolor endcolor)
that creates an image 11 pixels wide and 1 pixel high that is a blend
from startcolor to
endcolor.
startcolor and endcolor
should be RGB colors.
To compute the color for each pixel, you should call the
rgb-weighted-average procedure that you wrote in
part (c).
Use image-five-pixel-blend and its helper as a
model for your procedure(s).
e. Use image-11-pixel-blend to compute color blends from
three colors to their pseudo-complements. What do you notice about
the colors in the middle of these blends? Why do you get those
colors?
Important Evaluation Criteria
We intend to evaluate your assignment on the correctness and elegance of
your solution. That is, is what you've done something that could be
reasonably considered a blend, and have you chosen a technique that is
clear and easy to understand.