xxxxxxxxxx
int [] position = new int[4];
float r = 0;
float b = 0;
float g = 0;
void setup() {
size(1000, 1000);
position[0] = 0;
position[1] = 250;
position[2] = 500;
position[3] = 750;
frameRate(5);
}
void draw() {
// Color the background and draw lines to divide the window in quadrants.
background(r,g,b);
stroke(255);
int w = width;
int h = height;
for(int i = 0; i < 4; i++){
line(250*i,0,250*i,height);
line(0,250*i,width,250*i);
}
// If the mouse is on the right hand side of the window, increase red.
// Otherwise, it is on the left hand side and decrease red.
if (mouseX > width/2) {
r = r + 1;
} else {
r = r - 1;
}
// If the mouse is on the bottom of the window, increase blue.
// Otherwise, it is on the top and decrease blue.
if (mouseY > height/2) {
b = b + 1;
} else {
b = b - 1;
}
float x = position[int(random(0,4))];
float y = position[int(random(0,4))];
fill(255);
rect(x, y, 250, 250);
if((mouseX > x && mouseX < x+250) && (mouseY > y && mouseY < y+250)){
fill(200,220,120);
ellipse(x+125,y+125,100,100);
}
// Constrain all color values to between 0 and 255.
r = constrain(r,0,255);
g = constrain(g,0,255);
b = constrain(b,0,255);
}