#include<stdio.h> #include<graphics.h> #include<math.h> #include<time.h> #define round(a)((int)(a+0.5)) int main() { int gd=DETECT,gm=VGAMAX,sx=0,sy=0,mx=0,my=0,hx=0,hy=0,f=0; float hour,min; time_t now; struct tm *t; initgraph(&gd,&gm,"NULL"); setcolor(2); circle(300,300,100); setcolor(14); circle(300,300,110); setcolor(3); circle(300,300,120); do { time(&now); t=localtime(&now); if(f!=0) { setcolor(BLACK); line(300,300,sx,sy); line(300,300,mx,my); line(300,300,hx,hy); } hour=(t->tm_hour)%12+((float)t->tm_min/60.0); min=t->tm_min+((float)t->tm_sec/60.0); sx=300+round(90*cos(3.1412*(270+(6*t->tm_sec))/180)); sy=300+round(90*sin(3.1412*(270+(6*t->tm_sec))/180)); mx=300+round(90*cos(3.1412*(270+(6*min))/180)); my=300+round(90*sin(3.1412*(270+(6*min))/180)); hx=300+round(50*cos(3.1412*(270+(30*hour))/180)); hy=300+round(50*sin(3.1412*(270+(30*hour))/180)); outtextxy(294,380,"6"); outtextxy(380,300,"3"); outtextxy(293,220,"12"); outtextxy(220,300,"9"); setcolor(YELLOW); line(300,300,mx,my); setcolor(10); line(300,300,hx,hy); setcolor(RED); line(300,300,sx,sy); f=1; }while(!kbhit()); printf("Current time %d:%d:%d",t->tm_hour,t->tm_min,t->tm_sec); getch(); while(!kbhit()); closegraph(); return 0; }
Sunday, October 24, 2010
Analog clock

Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment