Skip to content

Instantly share code, notes, and snippets.

@hanneshier
Created February 24, 2015 20:28
Show Gist options
  • Save hanneshier/032531a10d50b5591631 to your computer and use it in GitHub Desktop.
Save hanneshier/032531a10d50b5591631 to your computer and use it in GitHub Desktop.
clock with time zone
int timeZone = 0;
void setup() {
size(500,500);
frame.setResizable(true);
noFill();
ellipseMode(CENTER);
textAlign(CENTER,CENTER);
}
void draw() {
int timeS = second();
int timeM = minute();
int timeH = hour() + timeZone;
background(0);
analogUhr(width/2, height/2, gr(width, height, 3), timeS, timeM, timeH, 1, 1, 1);
digitalUhr(50+gr(width, height, 25), 0+gr(width, height, 25), gr(width, height, 25), timeS, timeM, timeH);
if(timeZone>0){
text("MEZ+"+timeZone, width/2, 20);
} if(timeZone<0) {
text("MEZ"+timeZone, width/2, 20);
} if(timeZone==0) {
text("MEZ", width/2, 20);
}
}
void analogUhr(int x, int y, int g, int s, int m, int h, int cr, int cg, int cb) {
//fill(cr,cg,cb);
stroke(255);
strokeWeight(max(1, g/100));
ellipse(x, y, g*2, g*2);
// Stundenzeiger
strokeWeight(max(1, g/10));
line(x, y, x+(g-g/4)*cos(radians(h*30-90)), y+(g-g/4)*sin(radians(h*30-90)));
// Minutenzeiger
strokeWeight(max(1, g/50));
line(x, y, x+(g-g/25)*cos(radians(m*6-90)), y+(g-g/25)*sin(radians(m*6-90)));
// Sekundenzeiger
stroke(255,0,0);
strokeWeight(max(1, g/100));
line(x, y, x+g*cos(radians(s*6-90)), y+g*sin(radians(s*6-90)));
}
void digitalUhr(int x, int y, int g, int s, int m, int h) {
textSize(g);
text(h+":"+m+":"+s, x, y);
}
int gr(int breite, int hohe, int faktor) {
if(breite<=hohe){
return breite/faktor;
} else {
return hohe/faktor;
}
}
void keyPressed() {
if(keyCode == LEFT) {
timeZone -= 1;
}
if(keyCode == RIGHT) {
timeZone += 1;
}
if(key == 'r') {
timeZone = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment