/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ /*############### CLOCK.C ###############*/ /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> #include <math.h> #define X(a,b,c) x=a*cos(b*c*pi/180.0-pi/2)+midx; #define Y(a,b,c) y=a*sin(b*c*pi/180.0-pi/2)+midy; #define d(a,b,c) X(a,b,c);Y(a,b,c);line(midx,midy,x,y) #define pi 3.1415926 void main(void) { float x,y; int gdriver = DETECT, gmode, errorcode; int midx, midy,l,x1,x2,y1,y2; int radius = 100; struct time t; float h,m,s; int i; /* initialize graphics */ initgraph(&gdriver, &gmode, " "); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } setwritemode(1); /*she zhi wei fu gai xing shi,zuo yong shi*/ /* mei hua yi ci xian jiou qing chu yi ci*/ /*yi xia shi de dao yuan xi zuo biao */ midx = getmaxx() / 2; midy = getmaxy() / 2; setbkcolor(1); /*bei jing yan se wei BLUE*/ setcolor(2); /*she zhi li mian circle de color*/ circle(midx, midy, radius); /* draw the li mian circle */ setcolor(5); /*she zhi wai mian circle de color*/ circle(midx,midy,radius+5); /*draw wai mian de circle*/ setcolor(3); /*she zhi yuan xin de color*/ circle(midx, midy, 2); /*draw the center of the circle*/ /*the following lines are drawing the KE_DU pan */ for(i=0;i<60;i++) { if(i%5==0) l=15; else l=5; x1=100*cos(i*6*pi/180)+midx; y1=100*sin(i*6*pi/180)+midy; x2=(100-l)*cos(i*6*pi/180)+midx; y2=(100-l)*sin(i*6*pi/180)+midy; line(x1,y1,x2,y2); }
/*get the time*/ gettime(&t); h=t.ti_hour; m=t.ti_min; s=t.ti_sec; /*draw the hour_hand*/ setcolor(7); d(60,(h+(float)m/60),30);/*这一行是很关键的。有了这一行时针就可以随着 */ /*分针的移动而随时移动了,从而改变了原来的只有*/ /*到整点时针才能变动的局限 */
/*draw the min_hand*/ |