Code
ColoredRect crL;
ColoredRect crR;
void setup(){
size (300, 300);
crL = new ColoredRect(LEFT, 0.5);
crR = new ColoredRect(RIGHT, 0.5);
}
void draw(){
background(0);
crL.render();
crR.render();
chooseMyColor();
drawMyRect();
}
void chooseMyColor(){
// You can ask the ColoredRects various questions about them
float crL_Red = crL.getRed(); // returns a value from 0...1
float crL_Green = crL.getGreen(); // returns a value from 0...1
float crL_Blue = crL.getBlue(); // returns a value from 0...1
float crL_Hue = crL.getHue(); // returns a value from 0...1
float crL_Sat = crL.getSat(); // returns a value from 0...1
float crL_Bri = crL.getBri(); // returns a value from 0...1
float crL_Width = crL.getWidth(); // returns a value from 0...1
float crR_Red = crR.getRed(); // returns a value from 0...1
float crR_Green = crR.getGreen(); // returns a value from 0...1
float crR_Blue = crR.getBlue(); // returns a value from 0...1
float crR_Hue = crR.getHue(); // returns a value from 0...1
float crR_Sat = crR.getSat(); // returns a value from 0...1
float crR_Bri = crR.getBri(); // returns a value from 0...1
float crR_Width = crR.getWidth(); // returns a value from 0...1
// here is where you would set the fill color for your part,
// the right hand side of the canvas.
// here's where you would compute your new color, based on the properties of the CR.
// here's a simple example, which produces a fill of pink..
//Average 2 sides
colorMode(RGB, 1.0);
float r = (crL_Red + crR_Red)/2;
float g = (crL_Green + crR_Green)/2;
float b = (crL_Blue + crR_Blue)/2;
fill(r,g,b);
//Average the compliments of both sides
//colorMode
float newHueR = (crR_Hue+.5);
if(newHueR>1){
newHueR = newHueR - 1;
}
if(newHueR<0){
newHueR = newHueR * -1;
}
float newHueL = (crL_Hue+.5);
if(newHueL>1){
newHueL = newHueL - 1;
}
if(newHueL<0){
newHueL = newHueL * -1;
}
float newHue=(newHueL+newHueR)/2;
float newSat=(crL_Sat+crR_Sat)/2;
float newBri=(crL_Bri+crR_Bri)/2;
colorMode(HSB, 1.0);
fill(newHue, newSat, newBri);
}
void drawMyRect(){
// don't touch this
float crLx = width * crL.getWidth();
float crRx = width - (width * crR.getWidth());
rect (crLx,0, crRx-crLx, height);
}
040 -- Computational Color I: Due 10/20
Statement:Download this Processing project, and install it into your sketchbook. This program automatically changes the color and size of a rectangle on the left hand side of the canvas. Your objective is to set the color of the rectangle on the right hand-side of the canvas, so that it always presents a "pleasing complement" (whatever that means to you) to the changing left-hand rectangle. You are not permitted to change the code governing the left-hand rectangle. [This is a small exercise!]
If you would like a slightly more difficult challenge, this related project asks you to derive a color which serves to "negotiate the space" in between two randomly-changing colored regions.