The problem is that you put a rect() inside setup() and it will never be updated there so there is no way to change its color. In the sketch I made, all the rects() are drawn in draw().
I changed your code so that the one green rect() turns white when you click. The rect() is in draw() now and background() clears the old image which will be necessary if you want the rect()s to be able to vanish later.
To make more than one rect(), you have to store them in some kind of a data structure. An ArrayList is ideal for this because you can add / remove rect()s. Then, for every rect() that exists, you draw one with whatever color is appropriate.
Let me know if anything in the code below is confusing. It will be important that all of it makes sense before you start trying to add more rect()s.
- int c = 255;
- boolean colorDown = false;
- void setup() {
- size(300, 400);
- rectMode(CENTER);
- }
- void draw() {
- background(190);
-
- if (colorDown && c > 0) c--;
- fill(c, 255, c);
-
- rect(150, 200, 50, 50);
- }
- void mouseClicked() {
- colorDown = true;
- }