Timer button
in
Programming Questions
•
5 months ago
Hi there. I am a bit new to Processing so please forgive me if there are obvious answers to my question.
I am trying to create a button so that when the mouse is hovering over it, a timer is started which counts to 3 seconds and if the mouse has remained over the button for 3 seconds then the button is activated (i.e. it is filled black and outputs a number, say 1).
I have managed to figure this bit out, however I was wondering if anyone know how to keep the button activated and then if the mouse hovers over the button for another 3 seconds the button is then deactivated (i.e. returns to a blank fill and outputs a different number, say 0). I have tried a few things but cant seem to get any result.
Any help on this would be greatly appreciated.
Thank you :)
// here is the code i have so far
int begintime = 2;
int start;
float f,g,h,j;
float f_,g_;
boolean active;
int a = 255;
int a_ = 255;
void setup() {
size(400, 400);
f = 50;
g = 50;
h = 40;
j = 30;
f_ = 100;
g_ = 50;
}
void draw() {
background(255);
fill(a);
//list of buttons
ellipse(f,g,h,h);
fill(a_);
ellipse(f_,g_,h,h);
ellipse(mouseX,mouseY,30,30);
if (dist(f,g,mouseX,mouseY) < (h/2)+(j/2)) {
active = true;
int ms = millis()-start;
println(ms);
// int sec = frameCount/60;
int sec = ms/1000;
int timer = begintime - sec;
if (timer <= 0 && active == true) {
fill(a);
ellipse(f,g,h,h);
println("HELLO");
a = 0;
}
}
if (dist(f_,g_,mouseX,mouseY) < (h/2)+(j/2)) {
active = true;
int ms = millis()-start;
println(ms);
// int sec = frameCount/60;
int sec = ms/1000;
int timer = begintime - sec;
// int sec = frameCount/60;
if (timer <= 0 && active == true) {
fill(a_);
ellipse(f_,g_,h,h);
a_ = 0;
println("Jimmy");
}
}
else {
active = false; {
a = 255;
a_ = 255;
start = millis(); }
}
}
1