gettime(t);/*取得系统时间,保存在time结构类型的数组变量中*/ h=t[0].ti_hour; m=t[0].ti_min;
x=50*sin((h*60+m)/360*PI)+320; /*时针的x坐标值*/ y=180-50*cos((h*60+m)/360*PI); /*时针的y坐标值*/ line(320,180,x,y);/*在电子表中绘制时针*/
x1=80*sin(m/30*PI)+320; /*分针的x坐标值*/ y1=180-80*cos(m/30*PI); /*分针的y坐标值*/ line(320,180,x1,y1); /*在电子表中绘制分针*/
digitclock(260,333,digithour(h)); /*在数字时钟中,显示当前的小时值*/ digitclock(305,333,digitmin(m)); /*在数字时钟中,显示当前的分钟值*/ setwritemode(1);
/*规定画线的方式,如果mode=1,则表示画线时用现在特性的线
与所画之处原有的线进行异或(XOR)操作,实际上画出的线是原有线与现在规定 的线进行异或后的结果。因此, 当线的特性不变, 进行两次画线操作相当于没有 画线,即在当前位置处清除了原来的画线*/
for(count=2;k!=ESC&&k!=TAB;){ /*开始循环,直至用户按下ESC键结束循环*/ setcolor(12);/*淡红色*/
sound(500);/*以指定频率打开PC扬声器,这里频率为500Hz*/ delay(700);/*发一个频率为500Hz的音调,维持700毫秒*/ sound(200);/*以指定频率打开PC扬声器,这里频率为200Hz*/ delay(300);
/*以上两种不同频率的音调,可仿真钟表转动时的嘀哒声*/ nosound(); /*关闭PC扬声器*/ s=t[0].ti_sec; m=t[0].ti_min; h=t[0].ti_hour;
x2=98*sin(s/30*PI)+320; /*秒针的x坐标值*/ y2=180-98*cos(s/30*PI); /*秒针的y坐标值*/ setlinestyle(0,0,1); line(320,180,x2,y2); /*绘制秒针*/
/*利用此循环,延时一秒*/
while(t[0].ti_sec==s&&t[0].ti_min==m&&t[0].ti_hour==h) { gettime(t);/*取得系统时间*/ if(bioskey(1)!=0){ k=bioskey(0);
count=keyhandle(k); } }
setcolor(15);
digitclock(353,333,digitsec(s)+1);/*数字时钟增加1秒*/
setcolor(12); /*淡红色*/ x2=98*sin(s/30*PI)+320; y2=180-98*cos(s/30*PI); line(320,180,x2,y2);
/*用原来的颜色在原来位置处再绘制秒针,以达到清除当前秒针的目的*/
/*分钟处理*/
if(t[0].ti_min!=m){ /*若分钟有变化*/ /*消除当前分针*/ setcolor(15); /*白色*/ x1=80*sin(m/30*PI)+320; y1=180-80*cos(m/30*PI); line(320,180,x1,y1); /*绘制新的分针*/ m=t[0].ti_min;
digitclock(305,333,digitmin(m)); /*在数字时钟中显示新的分钟值*/ x1=80*sin(m/30*PI)+320; y1=180-80*cos(m/30*PI);
line(320,180,x1,y1); }
/*小时处理*/
if((t[0].ti_hour*60+t[0].ti_min)!=(h*60+m)){ /*若小时数有变化*/ /*消除当前时针*/ setcolor(15); /*白色*/
x=50*sin((h*60+m)/360*PI)+320;/*50:时钟的长度(单位:像素),320:圆心的x坐标值*/
y=180-50*cos((h*60+m)/360*PI); line(320,180,x,y); /*绘制新的时针*/ h=t[0].ti_hour;
digitclock(260,333,digithour(h)); x=50*sin((h*60+m)/360*PI)+320; y=180-50*cos((h*60+m)/360*PI); line(320,180,x,y); } } }
int keyhandle(int key) /*键盘控制 */
{ switch(key)
case TAB:; }
int digithour(double h)/*将double型的小时数转换成int型*/ {int i;
for(i=0;i<=23;i++) {if(h==i) return i;} }
int digitmin(double m)/*将double型的分钟数转换成int型*/ {int i;
for(i=0;i<=59;i++) {if(m==i) return i;} }
int digitsec(double s) /*将double型的秒钟数转换成int型*/ {int i;
for(i=0;i<=59;i++) {if(s==i) return i;} }
void digitclock(int x,int y,int clock)/*在指定位置显示数字时钟:时\\分\\秒*/ {char buffer1[10]; setfillstyle(0,2); bar(x,y,x+20,348); if(clock==60) clock=0; sprintf(buffer1,\ outtextxy(x,y,buffer1); }
void drawcursor(int count) /*根据count的值,画一个光标*/ {switch(count) {
case 1:line(424,315,424,325);break; case 2:line(465,315,465,325);break; case 3:line(505,315,505,325);break; } }
void clearcursor(int count) /*根据count的值,清除前一个光标*/
{switch(count) {
case 1:line(424,315,424,325);break; case 2:line(465,315,465,325);break; case 3:line(505,315,505,325);break; } }
huatu() {
int driver, mode=0,i,j;
driver=DETECT; /*自动检测显示设备*/
initgraph(&driver, &mode, \初始化图形系统*/
setlinestyle(0,0,3); /*设置当前画线宽度和类型:设置三点宽实线*/ setbkcolor(0);/*用调色板设置当前背景颜色*/ setcolor(9); /*设置当前画线颜色*/ line(5,5,635,5); line(5,5,5,475); line(635,5,635,475); line(5,475,635,475); line(5,235,320,5); line(320,5,635,235); line(635,235,320,400);
line(320,400,5,235); /*画主体框架的边直线*/ /*arc(int x, int y, int stangle, int endangle, int radius)*/ setcolor(15);
outtextxy(305,50,\显示标题*/ setcolor(7);
line(250,320,390,320); line(390,320,390,350); line(390,350,250,350); line(250,350,250,320); setcolor(5);
for(i=290;i<=336;i+=46) for(j=333;j<=340;j+=7){ setlinestyle(0,0,3);
circle(i,j,1); /*以(i, y)为圆心,1为半径画圆*/ }
/*绘制表示小时的圆点*/ setcolor(15);
for(i=0,mi=0,ho=0;i<=11;i++,ho++){ x=100*sin((ho*60+mi)/360*PI)+320; y=180-100*cos((ho*60+mi)/360*PI); setlinestyle(0,0,3);
circle(x,y,2); }
/*绘制表示分钟或秒钟的圆点*/ setcolor(11);
for(i=0,mi=0;i<=59;mi++,i++){ x=100*sin(mi/30*PI)+320; y=180-100*cos(mi/30*PI); setlinestyle(0,0,1); circle(x,y,1); }
/*在电子表的左边打印帮助提示信息*/ setcolor(12);
outtextxy(250,420,\
outtextxy(20,35,\ outtextxy(385,35,\ setcolor(10);
outtextxy(400,55,\
outtextxy(20,55,\ outtextxy(313,65,\ outtextxy(363,80,\ outtextxy(413,120,\ outtextxy(426,175,\outtextxy(413,225,\ outtextxy(370,273,\ outtextxy(316,286,\ outtextxy(263,275,\ outtextxy(219,233,\ outtextxy(205,177,\ outtextxy(214,120,\ outtextxy(263,80,\ setcolor(10);
circle(150,240,50); circle(150,240,45); circle(150,240,40); circle(150,240,35); circle(150,240,30); circle(150,240,25); circle(150,240,20); circle(150,240,15); circle(150,240,10); circle(150,240,05); circle(150,240,1); circle(490,240,50); circle(490,240,45);