I am working through Daniel Shiffmans great book "Learning Processing", here is my code. my problem is when I hold the mouse over a specific area for a long time, instead of staying black, it "resets" to white, until I move the mouse away - I am not sure why this happens. Any thoughts on this would be much appreciated!
Code://pract_exc_5_6_enhanced
//using logical operators to color one of four quadrants based on mouse position
//these are variable that color the quadrants
int a = 255; //top right quad
int b = 255; //top left quad
int c = 255; //bottom left quad
int d = 255; //bottom right quad
void setup() {
size(200,200);
background(255);
}
void draw() {
rectMode(CORNER);
stroke(0);
line(width/2,0,width/2,height); //vertical line down center of window
line(0,height/2,width,height/2); //horizontal line across center of window
//quadrant a - when the mouse moves over this area, fade into black, when the mouse leaves, fade into white
if(mouseX > width/2 && mouseY < height/2){
a = a - 1; //get darker
fill(a);
rect(width/2,0,width/2,height/2);
}
else{
a = a + 1; //get lighter
fill(a);
rect(width/2,0,width/2,height/2);
}
//quadrant b - when the mouse moves over this area, fade into black, when the mouse leaves, fade into white
if(mouseX < width/2 && mouseY < height/2){
b = b - 1; //get darker
fill(b);
rect(0,0,width/2,height/2);
}
else{
b = b + 1; //get lighter
fill(b);
rect(0,0,width/2,height/2);
}
//quadrant c - when the mouse moves over this area, fade into black, when the mouse leaves, fade into white
if(mouseX < width/2 && mouseY > height/2){
c = c - 1; //get darker
fill(c);
rect(0,height/2,width/2,height/2);
}
else{
c = c + 1; //get lighter
fill(c);
rect(0,height/2,width/2,height/2);
}
//quadrant d - when the mouse moves over this area, fade into black, when the mouse leaves, fade into white
if(mouseX > width/2 && mouseY > height/2){
d = d - 1; //get darker
fill(d);
rect(width/2,height/2,width/2,height/2);
}
else{
d = d + 1; //get lighter
fill(d);
rect(width/2,height/2,width/2,height/2);
}
//constrain the darkenesss variables
a = constrain(a,0,255);
b = constrain(b,0,255);
c = constrain(c,0,255);
d = constrain(d,0,255);
}