วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558

LAB 2 CLOCK Analog

void setup(){
  size(600,600);

}

void draw(){
  background(0);
  // set reference point of circle
  int X=300;
  int Y=300;
  // set diameter and radiuse
  int diameter=360;
  float r=diameter/2;
  // set body clock
  stroke(255);
  fill(255);
  ellipse(X,Y,diameter+40,diameter+40);
  fill(0);
  ellipse(X,Y,diameter,diameter);
 
 
  secondLine(r,X,Y);
  minuteLine(r,X,Y);
  hourLine(r,X,Y);

 
  stroke(255);
  point(X,Y);
 

}
// set start point of point2 in anyline
float pointX=0;
float pointY=0;

// MAKE function of second line
//r is radiuse x and y is reference point
void secondLine(float r,int X,int Y){

 
  // set angle of second line
  float angle=map(second(),0,60,0,TWO_PI)-HALF_PI;
 
  strokeWeight(3);
  stroke(255,0,0);
  //set point of x and y in point2 of line
  pointX=X+(r*0.8)*cos(angle);
  pointY=Y+(r*0.8)*sin(angle);
  line(X,Y,pointX,pointY);
   strokeWeight(7);
   point(X+r*cos(angle),Y+r*sin(angle));
}

// MAKE function of minute line
//r is radiuse x and y is reference point
void minuteLine(float r,int X,int Y){
  float angle =map(minute()+ norm(second(), 0, 60),0,60,0,TWO_PI)-HALF_PI;
  strokeWeight(4);
  stroke(0,255,0);
  pointX=X+(r*0.6)*cos(angle);
  pointY=Y+(r*0.6)*sin(angle);
   line(X,Y,pointX,pointY);
    strokeWeight(7);
   point(X+r*cos(angle),Y+r*sin(angle));
}

// MAKE function of Hour line
//r is radiuse x and y is reference point
void hourLine(float r,int X,int Y){
  float angle =map(hour()+ norm(minute(), 0, 60),0,24,0,TWO_PI*2)-HALF_PI;
  strokeWeight(5);
  stroke(0,0,255);
  pointX=X+(r*0.4)*cos(angle);
  pointY=Y+(r*0.4)*sin(angle);
   line(X,Y,pointX,pointY);
   strokeWeight(7);
   point(X+r*cos(angle),Y+r*sin(angle));
}





ไม่มีความคิดเห็น:

แสดงความคิดเห็น