We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When I specify a mousePressed-event over an area, I want the default stroke weight of 1 to go up to 4 and have a colour change of the stroke to pink. This works.
When I press the button again though, the code draws a default stroke weight over the thick pink stoke, without 'erasing' this thick pink stroke, whereas I would like the line to simply go back to: 'white' and 'default thickness of 1'.
Why doesn't the previous colored strokeWeight erase after the mousePressed-event? I'm very thankful for any advice!
Here's the code:
boolean button = false;
int x = 50;
int y = 50;
int w = 100;
int h = 75;
void setup() {
size(500,500);
}
void draw() {
if (button) {
stroke(#E55AD5);
strokeWeight(4);
strokeJoin(ROUND);
} else {
stroke(255);
strokeWeight(1);
}
noFill();
rect(x,y,w,h);
}
void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
button = !button;
}
}
Answers
https://Processing.org/reference/background_.html
https://Processing.org/reference/clear_.html
Thank you very much! I added ' background(175)' in the 'else'-block after strokeWeight(1), (see below), and now it works!
Thanks for the help, GoToLoop! Much appreciated!