#include "Conio.h"
#include "graphics.h"
#include "stdio.h"
#include "math.h"
#include "dos.h"
#include "time.h"
#define closegr closegraph
#define PI 3.1415926
void initgr(void)
{
int gd = DETECT, gm = 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd, &gm, "");
}
int main(void)
{
struct time tim;
int end_x,end_y,i,font_x,font_y,XX_sec,YY_sec,XX_hr,YY_hr,XX_min,YY_min;
float sec_radian,min_radian,hr_radian,font_radian;
int pan=1;
initgr();
while(!bioskey(1))
{
gettime(&tim);
sec_radian=(float)tim.ti_sec*((2*PI)/60);
min_radian=(float)tim.ti_min*((2*PI)/60);
hr_radian=(float)tim.ti_hour*((2*PI)/12)+min_radian/12;
setbkcolor(BLACK);
setcolor(BLUE);
circle(320,240,220);
circle(320,240,150);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(310,130,"clock");
if(pan==1)
{
setcolor(RED);
}
else
{
setcolor(BLACK);
line(320,240,XX_sec,YY_sec);
line(320,240,XX_min,YY_min);
line(320,240,XX_hr,YY_hr);
setcolor(RED);
}
end_x=320+80*sin(hr_radian);
end_y=240-80*cos(hr_radian);
line(320,240,end_x,end_y);
XX_hr=end_x;YY_hr=end_y;
end_x=320+125*sin(min_radian);
end_y=240-125*cos(min_radian);
line(320,240,end_x,end_y);
XX_min=end_x;YY_min=end_y;
end_x=320+140*sin(sec_radian);
end_y=240-140*cos(sec_radian);
line(320,240,end_x,end_y);
XX_sec=end_x;YY_sec=end_y;
pan=0;
setcolor(YELLOW);
circle(320,240,1);
circle(320,240,2);
setcolor(0xE9FD05);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
for(i=1;i<=12;i++)
{
font_radian=i*((2*PI)/12);
font_x=308+190*sin(font_radian);
font_y=230-190*cos(font_radian);
switch(i)
{
case 1: outtextxy(font_x,font_y,"1");break;
case 2: outtextxy(font_x,font_y,"2");break;
case 3: outtextxy(font_x,font_y,"3");break;
case 4: outtextxy(font_x,font_y,"4");break;
case 5: outtextxy(font_x,font_y,"5");break;
case 6: outtextxy(font_x,font_y,"6");break;
case 7: outtextxy(font_x,font_y,"7");break;
case 8: outtextxy(font_x,font_y,"8");break;
case 9: outtextxy(font_x,font_y,"9");break;
case 10: outtextxy(font_x,font_y,"10");break;
case 11: outtextxy(font_x,font_y,"11");break;
case 12: outtextxy(font_x,font_y,"12");
}
}
sleep(1);
/*cleardevice(); */
}
getch();
closegr();
return 0;
}
评论0