my code
// Dimmer Button
// I have a feeling this fade could be done better...
// declare and initialize variables
boolean button = false;
int x = 50;
int y = 50;
int w = 100;
int h = 75;
float change = 5; // fade rate
float gs; //greyscale from 0-255
void setup() {
size(200,200);
}
void draw() {
background(gs);
stroke(255);
// if mouse is pressed over the button
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {
button = true;
} else {
button = false;
}
// this is the fade
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; // this creates the fade
// declaring my constraints
gs = constrain(gs,0,254);
}