Code

void setup(){
size (200,200);
smooth();
noStroke();
}

float x1 = 20;
float y1 = 20;
float w1 = 20;
float h1 = 20;

float x2 = x1*2;
float y2 = y1*2;
float w2 = w1*2;
float h2 = h1*2;

void draw(){
  background(255);
  rect(x2,y2,w2,h2);
  if(((mouseX>x1) && (mouseX<2*x1) && (mouseY>y1) && (mouseY<2*y1))){
    fill(255,0,0);
  } else{
    fill(0);
  }
   rect(x1,y1,w1,h1);
  if ((mouseX>x2) && (mouseX<2*x2) && (mouseY>y2) && (mouseY<2*y2)){
    fill(0,255,0);
  } else{
    fill(0);
  }
}

...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