编写一个桌面闹钟源程序


/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
/*############### 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();
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值