Hi everyone. I’m currently trying to create several shapes where each shape can be clicked on seperately. I currently have an array of rectangles which are being drawn onto the screen. I want to be able to click on a rectangle and have it change color without having the other rectangles change color as well. Somehow the code I have right now doesn’t work as nothing happens at all. What am I doing wrong?
int[] rects = new int[3];
int x = 20;
int y = 100;
int h = 100;
int marge = 20;
int w = ((600 - ((rects.length+1)*marge)) / rects.length);
void setup() {
size(600, 500);
}
void draw() {
drawRect();
}
void mousePressed() {
for (int i = 0; i < rects.length; i++) {
if (mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) {
fill(0);
}
else {
fill(255);
}
}
}
void drawRect() {
for(int i = 0; i < rects.length; i++) {
rect(x, y, w, h);
x += w + marge;
}
}