class Clock{
PVector position;
float radius;
PFont bigF;
String dateString="";
Clock(float x, float y, float r){
position=new PVector(x,y);
radius=r;
bigF=createFont("Arial bold",14);
}
Clock(){
position=new PVector(width/2,height/2);
radius=width/2-10;
bigF=createFont("Arial bold",14);
}
void draw(){
pushStyle();
smooth();
pushMatrix();
translate(position.x,position.y);
drawClockFace();
drawDate();
//resetMatrix();
// draw seconds
pushMatrix();
int s=second();
strokeWeight(1);
rotate((1.0*s/60)*TWO_PI);
line(0,0,0,-radius);
popMatrix();
// draw minute
pushMatrix();
int m=minute();
strokeWeight(3);
rotate((1.0*m/60)*TWO_PI);
line(0,0,0,-radius*0.8);
popMatrix();
// draw hour
pushMatrix();
int h=hour();
strokeWeight(5);
rotate((1.0*h/12)*TWO_PI);
// pluss part of hour
float dv=(TWO_PI/12)*(1.0*m/60);
rotate(dv);
line(0,0,0,-radius*0.5);
popMatrix();
popMatrix();
popStyle();
}
void drawClockFace(){
pushStyle();
strokeWeight(1);
fill(#EFF029);
ellipseMode(RADIUS);
ellipse(0,0,radius,radius);
fill(0);
for(int ix=0; ix < 12; ix++){
pushMatrix();
rotate((1.0*ix/12)*TWO_PI);
translate(0,radius);
ellipse(0,0,3,3);
popMatrix();
}
popStyle();
}
void drawDate(){
pushStyle();
fill(0);
textFont(bigF);
pushMatrix();
translate(0,radius/2);
textAlign(CENTER,CENTER);
if(dateString.length()==0)
text(""+day()+"."+month()+"."+year(),0,0);
else
text(dateString,0,0);
popMatrix();
popStyle();
}
void setDateString(String S){
dateString=S;
}
}