CPSC 120 Postlab 4: Color Bars
Due by 3:00 pm on Friday, September 25, 2009
To see this in color go to the course web page!
Overview
For artists that work digitally, the color accuracy of a display
can have tremendous implications. For
example, if an artist's display desaturates green slightly, then an image
with people would be printed with sickly green looking people. In order
to remedy this, the color of the device must be calibrated to a range of
known colors. The colors for calibration are often displayed using
vertical bars of color. In this assignment you will write a program
that can generate color bars by interpolating two different colors.
Your program should display a window with five vertical color bars of equal
size. The left and right color bars should be the color of one of the static
fields of the Color class (Color.black, Color.blue, Color.cyan, etc.).
The bar in the middle should be a 50%-50% blend of the right and left color
bars. The center right and center left color bars should be 75%-25% blend of
the right and left color bars (switching which is 75% and which is 25% to
create two different colors).
In order to accomplish this you will need to interpolate colors, which can
be acheived by interpolating each of the rgb values that constitute a
color. In order to linearly interpolate two numbers you can use the
following equation:
xi = x1 * (p1 / 100) + x2 * (p2 / 100)
Where xi is a value that is p1 percent of x1
and p2 percent of x2. Note that p1 and
p2 must sum to 100.
Planning Your Program
- First declare your variables. You will probably
need variables for each of the colors that will be drawn.
The Color objects for the left and right color bars can be initialized
when the variables are declared. The value of the other three colors,
however, must be calculated from the left and right colors. In order to
calculate the remaining colors using the interpolation equation above you
can read the rgb values using the get methods (getRed(), getGreen(), and
getBlue()) of the Color class. Once you calculate new rgb values you
can use the constructor of the Color class to create a new Color
object.
- When you have variables representing all five colors you can draw five
filled rectangles to the window, one of each color in the appropriate location.
Other Requirements
As usual, use good programming techniques. You should use good
variable names, constants where appropriate, whitespace, and
correct indentation and alignment of statements.
Be sure to put your name, the file name, and a description of the program
in the header.
The program should be broken up into logical sections and each section should be
documented with a brief description of what it does.
What to turn in
Turn in hardcopy of your program and e-mail the .java file to your
instructor @roanoke.edu with cpsc120 post4 in the subject.