Monday, 30 April 2018

Simple Clock Animation Using Processing(with Code)





Find the code for above video below.

void setup(){

  size(800,800);
  background(0);
  strokeCap(SQUARE);
}

void draw(){

  fill(0);
  rect(0,0,800,800);

  int s=second();
  int h=hour();
  int m=minute();

  String time;

  if(h>=10)
    time=h+"";
  else
    time="0"+h;
  if(m<10)
    time=time+":0"+m;
  else
    time=time+":"+m;
  if(s<10)
    time=time+":0"+s;
  else
    time=time+":"+s;

  if(h>12)
    h=h-12;

  translate(400,400);
  rotate(radians(-90));

  noFill();
  strokeWeight(24);
  stroke(255);//Set your Color
  arc(0,0,400,400,0,((2*PI)/60)*s);

  stroke(255);//Set your Color
  arc(0,0,350,350,0,((2*PI)/60)*m);

  stroke(255);//Set your Color
  arc(0,0,300,300,0,((2*PI)/12)*h);

  rotate(radians(90));
  PFont font = createFont("Comic Sans MS", 40);
  textFont(font);
  fill(255);
  text(time, -80, 0);
}