Why does stokeWeight not erase after mousePressed event?

edited September 2017 in Questions about Code

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

Sign In or Register to comment.