Dimmer Switch

the code

// Dimmer Switch
// 2/10/11

boolean button = false;

int x = 50;
int y = 50;
int w = 100;
int h = 75;
float change = 5; // fade rate
float gs; //greyscale

void setup() {
size(200,200);
}

void draw() {
background(gs);
stroke(255);

if (button) {
change = -5;
fill(255,0,0);
} else {
change = 5;
fill(0,0,255);
}

background(gs);
rect(x,y,w,h);
gs = gs + change;
gs = constrain(gs,0,254);
}

void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h){ button = !button; } }