Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created October 27, 2014 10:34
Show Gist options
  • Save yoggy/04e5c50845d3bb048143 to your computer and use it in GitHub Desktop.
Save yoggy/04e5c50845d3bb048143 to your computer and use it in GitHub Desktop.
Clock clock;
void setup() {
size(200, 200);
clock = new Clock(width / 2, height / 2, width/2-20);
}
void draw() {
background(0);
noFill();
stroke(255);
clock.draw();
}
class Clock {
int x, y, r;
Clock(int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
}
void draw() {
stroke(255);
noFill();
strokeWeight(10);
ellipse(x, x, r*2, r*2);
int idc_w = 10;
strokeWeight(10);
line(x, y - r, x, y - r + idc_w);
line(x, y + r, x, y + r - idc_w);
line(x - r, y, x - r + idc_w, y);
line(x + r, y, x + r - idc_w, y);
int h = hour();
int m = minute();
int s = second();
int s_l = r - 15;
int m_l = r - 20;
int h_l = r - 40;
float fh = h / 12.0 + 1.0/12.0/60.0*m;
strokeWeight(8);
line(x, y, x + h_l * sin(fh * 2 * PI), y + h_l * -cos(fh * 2 * PI));
float fm = m / 60.0;
strokeWeight(5);
line(x, y, x + m_l * sin(fm * 2 * PI), y + m_l * -cos(fm * 2 * PI));
float fs = s / 60.0;
strokeWeight(2);
line(x, y, x + s_l * sin(fs * 2 * PI), y + s_l * -cos(fs * 2 * PI));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment