Code
boolean bchange = true;
int press;
int x= 100;
int y= 100;
int w= 100;
int h= 100;
void setup(){
size (300,300);
background (0);
fill(255);
}
void draw (){
if (bchange == false){
fill (0);
}
else{
fill (255);
}
rect(x,y,w,h);
}
void mousePressed(){
if (mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h){
press = press +1;
if (press == 2){
bchange = !bchange;
}
if (press== 5){
bchange = !bchange;
press = 0;
}
}
}
0302 - Maintaining state (click counter): Keeping a count of clicks
Statement:In a 300x300 pixel canvas with a colored background, create a 100x100 pixel reactive square, such that two clicks are required to turn it from white to black, but three clicks are required to turn it from black to white. Mouse clicks outside the reactive square area should have no effect!
Hint:Use one global variable to store how many times the user has clicked since the last flip. Use another to store whether or not the system is currently black or white...