CPSC 120 Postlab 4: Color Bars
Due by 4:00 p.m. on Monday October 4th
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 filled with five vertical color bars of equal
size. The left and right color bars should be randomly generated colors.
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 achieved 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.0) + x2 * (p2 / 100.0)
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 think about the variables you will need. You will probably
need variables for each of the colors that will be drawn - and
these will be Color objects. You will probably also want some
variables for your calculations (the amount of red, green, and
blue in each color).
The Color objects for the left and right color bars can be initialized
when the variables are declared using a method from lab for
generating random colors. 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
need to read the rgb values using the get methods (getRed(), getGreen(), and
getBlue()) of the Color class. For each color bar
you calculate new rgb values (3 values), then 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.
Each bar should be one fifth of the width of the window and the full height of the window.
When the window is resized the bars should also resize so that they fill the entire window.
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.
Submission
From your postlab4 directory, tar your code using the command:
tar czf yournamePost4.tgz .
To submit your code, copy the tar file containing your code
to the directory:
~ingram/CPSC120/yourname