Thursday, September 30, 2010

HW 4: Colors

For this homework you will implement a simple Color class which stores RGB colors prints them out and lets you mix colors.

Your program will have the constructors and methods such that this main:

 public static void main(String[] args) {
  //a constructor with all ints arguments, each is a number between 0 and 255.
  Color red = new Color(255,0,0);
  //a constructor that understands "red", "green" and "blue".
  Color blue = new Color("blue");
  //a constructor with all doubles as arguments, each is a number between 0 and 1.
  Color green = new Color(0.0, 1.0, 0.0);
  //if a number is out of range you push it back into the range!
  Color reallyGreen = new Color(0.0, 100, 0.0);
  //Mix colors by simply taking the average of each component (RGB).
  Color purple = red.mixWith(blue);
  System.out.println("purple=" + purple);
  purple = purple.mixWith(red);
  purple = purple.mixWith(red);
prints out these statements:

Those are hexadecimal numbers there, in the standard Hex triplet format. Notice how your code will not let the user create an illegal color.

Tip: your internal representation should use a number between 0 and 255 for each one of the channels (RGB). Also, try to make use of your own private methods.

The homework should be deposited in our dropbox by Thursday, October 7 @ 9am

No comments: