void setup() {
size(300, 300);
}
void draw() {
background(120);
int rectX = 30;
int rectY = 40;
int rectHeight = 50;
int rectWidth = 50;
if (insideRect(mouseX, mouseY, rectX, rectY, rectHeight, rectWidth)) {
fill(255);
}
else {
fill(120);
}
rect (rectX, rectY, rectHeight, rectWidth);
}
// boolean function returns either true or false
boolean insideRect(float px, float py, float rx, float ry, float rw, float rh) {
return px >= rx && px <= rx+rw && py >= ry && py <= ry+rh;
}
InsideRectangle Boolean Function
Here is an example of a function that returns a boolean, as opposed to a 'void' function. The insideRect() function returns true or false if a point is inside a rectangle.