Hi, im trying to create a switch function with a for structure to create a switch matrix. This is where im stuck:
Quote:color c = 255;
int x;
int y;
int w;
int h;
void setup() {
size(400,400);
smooth();
rectMode(CENTER);
}
void draw() {
background(#1F45AA);
for(int i = 40; i < 375; i = i+75) {
for(int j = 40; j < 375; j = j+75) {
button(i,j,50,50); //This is the button with the for structure
}}
}
void button(int tempx, int tempy, int tempw, int temph) { //This is the button function with parameters
x = tempx;
y = tempy;
w = tempw;
h = temph;
strokeWeight(5);
fill(c);
rect(x,y,w,h);
}
void mousePressed() {
if(c == 255 && mouseX <= x + w/2 && mouseX >= x - w/2 && mouseY >= y - h/2 && mouseY <= y + h/2) { //This line is supposed to constrain the mouse to fill only one instance of the array ... but it dont work...
c = 0;
} else {
c = 255;
}
}
When i remove the constrains i can switch all the buttons at once and it work! but when i use them in the mousePressed function none works...
here is the code without constrains:
color c = 255;
int x;
int y;
int w;
int h;
void setup() {
size(400,400);
smooth();
rectMode(CENTER);
}
void draw() {
background(#1F45AA);
for(int i = 40; i < 375; i = i+75) {
for(int j = 40; j < 375; j = j+75) {
button(i,j,50,50);
}}
}
void button(int tempx, int tempy, int tempw, int temph) {
x = tempx;
y = tempy;
w = tempw;
h = temph;
strokeWeight(5);
fill(c);
rect(x,y,w,h);
}
void mousePressed() {
if(c == 255) {
c = 75;
} else {
c = 255;
}
}
please help me fix it,
Odin