Using mousePressed...
in
Programming Questions
•
8 months ago
Is mousePressed the best check here? Tried using noLoop but it obviously stops everything.
void setup() {
size(1250, 400);
background(255);
}
void draw() {
if (mouseX > 50 && mouseX < 150 && mousePressed == true) {
switchOn(50,100);
textSize(40);
fill(0);
text("128", 65, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(50,100);
}
if (mouseX > 200 && mouseX < 300 && mousePressed == true) {
switchOn(200,100);
textSize(40);
fill(0);
text("64", 225, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(200,100);
}
if (mouseX > 350 && mouseX < 450 && mousePressed == true) {
switchOn(350,100);
textSize(40);
fill(0);
text("32", 375, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(350,100);
}
if (mouseX > 500 && mouseX < 600 && mousePressed == true) {
switchOn(500,100);
textSize(40);
fill(0);
text("16", 525, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(500,100);
}
if (mouseX > 650 && mouseX < 750 && mousePressed == true) {
switchOn(650,100);
textSize(40);
fill(0);
text("8", 685, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(650,100);
}
if (mouseX > 800 && mouseX < 900 && mousePressed == true) {
switchOn(800,100);
textSize(40);
fill(0);
text("4", 835, 75);
//noLoop();
} else if (mousePressed == false) {
switchOff(800,100);
}
if (mouseX > 950 && mouseX < 1050 && mousePressed == true) {
switchOn(950,100);
textSize(40);
fill(0);
text("2", 985, 75);
//noLoop();
} else {
switchOff(950,100);
}
if (mouseX > 1100 && mouseX < 1200 && mousePressed == true) {
switchOn(1100,100);
textSize(40);
fill(0);
text("1", 1140, 75);
} else {
switchOff(1100,100);
}
}
void switchOn(int x, int y) {
fill(50);
strokeWeight(3);
rect(x, y, 100, 250);
fill(100);
rect(x, y+125, 100, 125);
textSize(32);
fill(225);
text("ON", x+29, y+195);
}
void switchOff(int x, int y) {
fill(100);
strokeWeight(3);
rect(x, y, 100, 250);
fill(50);
rect(x, y+125, 100, 125);
textSize(32);
fill(225);
text("OFF", x+19, y+75);
}
1