/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
/*############### 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*/
setcolor(14);
d(75,m,6);
/*draw the sec_hand*/
setcolor(4);
d(90,s,6);
while(!kbhit())
{
while(t.ti_sec==s)
gettime(&t);
gotoxy(1,1);
printf("The current time is: %2d:%02d:%02d.%02d",
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
sound(150);
delay(100);
sound(300);
nosound();
setcolor(4);
d(90,s,6);
s=t.ti_sec;
d(90,s,6);
if (t.ti_min!=m)
{
setcolor(14);
d(75,m,6);
m=t.ti_min;
d(75,m,6);
}
setcolor(7);
d(60,h+(float)m/60.0,30);
h=(float)t.ti_hour;
d(60,h+(float)m/60.0,30);
if(t.ti_hour!=(int)h)
{
setcolor(7);
d(60,h,30);
h=t.ti_hour;
d(60,h,30);
sound(500);
delay(200);
nosound();
sound(1000);
delay(100);
nosound();
}
}
getch();
closegraph();
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |