Code
void setup (){
size (300,300);
background (255);
}
void draw (){
noStroke ();
int x1 = 50;
int y1 = 50;
int w1 = 100;
int h1 = 100;
int x2 = 150;
int y2 = 150;
int w2 = 100;
int h2 = 100;
boolean insideBox1 = (mouseX >=x1 && mouseX<=x1+w1 && mouseY>=y1 && mouseY<=y1+h1);
boolean insideBox2 = (mouseX >=x2 && mouseX<=x2+w2 && mouseY>=y2 && mouseY<=y2+h2);
if (insideBox1) {
fill (255,0,0);
rect (x1,y1,w1,h1);
}
else {
fill (0);
rect (x1,y1,w1,h1);
}
if (insideBox2) {
fill (255,0,0);
rect (x2,y2,w2,h2);
}
else {
fill (0);
rect (x2,y2,w2,h2);
}
}
...Quiz 030 (September 17): Two Sensitive Square Regions
Statement:Given two rectangles, defined with (x1,y1,w1,h1) and (x2,y2,w2,h2): Create an interactive program such that when the mouse is hovering over a given rectangle, that region is RED, but when the mouse is not hovering within that area, the rectangle is some other color.
hide statement