Last active
January 15, 2016 11:47
-
-
Save denkspuren/c277c2eaa7c0f969068a to your computer and use it in GitHub Desktop.
Stopwatch demonstrating use of millis(), arc() and text()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Stopwatch by @denkspuren | |
Start and Stop by pressing space-bar. | |
Program requires some startup time to load fonts | |
used by text(). | |
*/ | |
// http://www.thm.de/site/corporate-design/hausfarben.html | |
// http://www.farbtabelle.at/farben-umrechnen/ | |
color THMGreen = color(128, 186, 36); | |
color THMGrey = color(74, 92, 102); | |
color THMRed = color(184, 0, 64); | |
color THMYellow = color(255,179,0); | |
color WHITE = color(255,255,255); | |
final float ONEBY60 = TWO_PI/60; | |
final float ONEBY10 = TWO_PI/10; | |
float t, t_start = 0; // time | |
int tenths, secs, mins; | |
boolean run = false; | |
void setup() { | |
size(400,300); | |
background(THMGreen); | |
noStroke(); | |
} | |
void draw() { | |
background(THMGreen); | |
fill(THMGrey); | |
if (run) t = millis() - t_start; | |
tenths = int(t/100) % 10; | |
secs = int(t/1000) % 60; | |
mins = int(t/1000/60) % 60; | |
fill(THMYellow); | |
arc(200,150,250,250,-HALF_PI,-HALF_PI + (60 - mins) * ONEBY60); | |
fill(THMGrey); | |
arc(200,150,200,200,-HALF_PI + secs * ONEBY60,3*HALF_PI); | |
fill(THMRed); | |
arc(200,150,100,100,-HALF_PI+(tenths-1)*ONEBY10,-HALF_PI+(tenths+0)*ONEBY10); | |
fill(WHITE); | |
text(mins+" mins "+secs+"."+tenths+" secs",10,20); | |
} | |
void keyPressed() { | |
if (key == ' ') { // ' ' is the SPACE character | |
if (!run) t_start = millis(); | |
run = !run; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment