Created
April 4, 2015 18:29
-
-
Save 3846masa/2a1ec2df02f18e19fd14 to your computer and use it in GitHub Desktop.
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
AnalogClock clock; | |
void setup() { | |
size(400, 400); | |
clock = new AnalogClock(width/2, height/2, width/2); | |
clock.setFillColor(color(255)); | |
clock.setStrokeWeight(5); | |
} | |
void draw() { | |
background(128); | |
clock.draw(); | |
} | |
class AnalogClock { | |
int x, y, r, strokeWeight; | |
int timelag; | |
color fillColor = color(255, 0), strokeColor = color(0); | |
AnalogClock(int _x, int _y, int _r) { | |
this.x = _x; this.y = _y; this.r = _r; | |
this.setup(); | |
} | |
void setStrokeWeight(int _w) { | |
this.strokeWeight = _w; | |
} | |
void setStrokeColor(color _c) { | |
this.strokeColor = _c; | |
} | |
void setFillColor(color _c) { | |
this.fillColor = _c; | |
} | |
private void setup() { | |
int sec = second(); | |
while(sec == second()) { | |
timelag = millis(); | |
} | |
} | |
void draw() { | |
pushStyle(); | |
fill(fillColor); | |
stroke(strokeColor); | |
strokeWeight(this.strokeWeight); | |
ellipse(x, y, r*2, r*2); | |
float milli_sec = (millis() - timelag)%1000; | |
float sec_rad = TWO_PI * (second() + milli_sec / 1000.0) / 60.0; | |
float min_rad = (TWO_PI * minute() + sec_rad) / 60.0; | |
float hour_rad = (TWO_PI * hour() + min_rad) / 12.0; | |
pushMatrix(); | |
translate(x, y); | |
rotate(-PI/2); | |
line(0, 0, r*0.5*cos(hour_rad), r*0.5*sin(hour_rad)); | |
line(0, 0, r*0.8*cos(min_rad), r*0.8*sin(min_rad)); | |
line(0, 0, r*0.95*cos(sec_rad), r*0.95*sin(sec_rad)); | |
popMatrix(); | |
popStyle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment