Constrain() function / mouse click on button

please format code with </> button * homework policy * asking questions

Hi!! I need help in understanding how to use the constrain() function. I want to be able to click on a rectangle and have it change colors, however, I want it to change colors only when I click on the rectangle how do I do that?

1 Like

constrain has not to do with it

void mousePressed() {

  if (mouseX >= x && 
      mouseX <= x+widthRect && 
      mouseY >= y && 
      mouseY <= y+heightRect) {
    // do something 
  } else {
    // nothing