#include <graphics.h>
#include <math.h>
#include <stdio.h>
#include <dos.h>
#define pi 3.1415926
main()
{
int gdriver,gmode,errorcode;
int x,y,i,angleHou,angleMin,angleSec;
long size;
char text[2],*buf;
struct time tim;
detectgraph(&gdriver,&gmode);
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("graphicx error: %s\n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
exit(1);
}
initgraph(&gdriver,&gmode,"");
if(errorcode!=grOk)
{
printf("graphicx error: %s\n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
exit(1);
}
/*draw three circles*/
setbkcolor(1);
setcolor(100);
circle(300,250,150);
setcolor(50);
circle(300,250,145);
setcolor(150);
circle(300,250,140);
/*set the hour's number*/
for(i=1;i<=12;i++)
{
x=300+130*sin((i*30)*pi/180);
y=250-130*cos((i*30)*pi/180);
sprintf(text,"%d",i);
outtextxy(x,y,text);
}
/*set the minute's number*/
for(i=1;i<=60;i++)
{
x=300+130*sin((i*6)*pi/180);
y=250-130*cos((i*6)*pi/180);
setcolor(255);
outtextxy(x,y,".");
}
size=imagesize(150,100,450,400);
buf=malloc(size);
getimage(150,100,450,400,buf);
/*get the time*/
while(1)
{ gettime(&tim);
angleHou=tim.ti_hour;
angleMin=tim.ti_min;
angleSec=tim.ti_sec;
putimage(150,100, buf, COPY_PUT);
/*count the position */
second(angleSec);
minute(angleMin);
hour(angleHou);
}
}
second(int angleSec)
{
int x,y;
while(kbhit())
{
closegraph();
exit(1);
}
x=300+115*sin((angleSec*6)*pi/180);
y=250-115*cos((angleSec*6)*pi/180);
setcolor(3);
line(300,250,x,y);
}
minute(int angleMin)
{
int x,y;
x=300+110*sin((angleMin*6)*pi/180);
y=250-110*cos((angleMin*6)*pi/180);
setcolor(4);
line(300,250,x,y);
}
hour(int angleHou)
{ int x,y,i,angleMin;
struct time tim;
gettime(&tim);
angleMin=tim.ti_min;
i=(angleMin*5)/60;
x=300+100*sin((angleHou*30+i*6)*pi/180);
y=250-100*cos((angleHou*30+i*6)*pi/180);
setcolor(5);
line(300,250,x,y);
}