Hi!
I’m trying to add a stopwatch to my clock. When I start the program the clock shows the current time and I want to add a stopwatch that starts when the mouse is clicked. The clock itself works but I can’t get my stopwatch to work, I want the clockhands to go to 12 and that the digital clock resets to 0 and starts counting until i click again and the current time is displayed again. Here’s what I have so far:
int i = 0;
int h = hour();
int m = minute();
int s = second();
boolean stopwatch = false;
void setup()
{
size(500, 500);
}
void draw()
{
background(255);
clock();
lines();
clockhands();
digitalclock();
if (stopwatch)
{
s++;
int s = second();
int m = minute();
int h = hour();
}
else
{
int s = second();
int m = minute();
int h = hour();
}
}
void clock()
{
translate(width/2, height/2);
stroke(0);
fill(255);
strokeWeight(2);
ellipse(0, 0, 300, 300);
strokeWeight(8);
stroke(0);
point(0, 0);
}
void lines()
{
pushMatrix();
for (int i = 0; i < 60; i++)
{
if (i % 5 == 0)
{
stroke(0);
strokeWeight(2);
line(0, -140, 0, -145);
}
else
{
stroke(0);
strokeWeight(1);
line(0, -140, 0, -145);
}
rotate(radians(6));
}
popMatrix();
}
void clockhands()
{
int h = hour();
int m = minute();
int s = second();
pushMatrix();
rotate(radians(h*30));
stroke(0); // hours
strokeWeight(3);
line(0, 0, 0, -100);
popMatrix();
pushMatrix();
rotate(radians(m*6));
stroke(150); // minutes
strokeWeight(2);
line(0, 0, 0, -140);
popMatrix();
pushMatrix();
rotate(radians(s*6));
stroke(229, 79, 55); // seconds
strokeWeight(1);
line(0, 0, 0, -140);
popMatrix();
}
void digitalclock()
{
pushMatrix();
int h = hour();
int m = minute();
int s = second();
PFont digital;
digital = loadFont("PingFangHK-Ultralight-48.vlw");
textFont(digital, 25);
fill(0);
text(h + ":" + nf(m, 2) + ":" + nf(s, 2), -45, 110);
popMatrix();
}
void mousePressed()
{
stopwatch = !stopwatch;
}
I’m not good with boolean and events since I just started learning, hopefully you can give me some tipps for my problems. Thanks!!