该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
int m=350,n=160;
int m2=350,n2=100,i2=0;
int m3=350,n3=70,i3=0;
/*程序存在2个BUG
1 指针在转动时会擦掉钟框,指针会擦掉先前别的指针
2 三针模块有很多重复代码,没有分离成子函数*/
void second(int i) /*秒针转动*/
{ int j,t1,t2;
struct arccoordstype arcinfo;
setcolor(0);
line(350,250,m,n);
setcolor(0);
t1=(540-(90+i*6))%360;
t2=(540-(96+i*6))%360;
arc(350,250,t1,t2,90);
getarccoords(&arcinfo); /*获取顶点的坐标 */
setcolor(5);
line(350,250,arcinfo.xend,arcinfo.yend);
m= arcinfo.xend;
n=arcinfo.yend;
if(m==m2) {setcolor(6); /*控制前针被擦除,运行没起作用*/
line(350,250,arcinfo.xend,arcinfo.yend);}
for(j=0;j<10;j++)
delay(55000);
/*用黑色覆盖掉过时的针*/
}
void minute() /*分针转动*/
{ int t1,t2;
struct arccoordstype arcinfo;
setcolor(0);
line(350,250,m2,n2);
setcolor(0);
t1=(540-(90+i2*6))%360;
t2=(540-(96+i2*6))%360;
arc(350,250,t1,t2,150); i2++; i2=i2%60;
getarccoords(&arcinfo); /*获取顶点的坐标 */
setcolor(6);
line(350,250,arcinfo.xend,arcinfo.yend);
m2= arcinfo.xend;
n2=arcinfo.yend;
}
void hour() /*时针转动*/
{ int t1,t2;
struct arccoordstype arcinfo;
setcolor(0);
line(350,250,m3,n3);
setcolor(0);
t1=(540-(90+i3*6))%360;
t2=(540-(96+i3*6))%360;
arc(350,250,t1,t2,180); i3++; i3=i3%60;
getarccoords(&arcinfo); /*获取顶点的坐标 */
setcolor(8);
line(350,250,arcinfo.xend,arcinfo.yend);
m3= arcinfo.xend;
n3=arcinfo.yend;
}
void main()
{
int driver,mode,i,j=0;
struct arccoordstype arcinfo;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,""); /*转化显示模式*/
for(i=0;i<12;i++){ /*画出钟框,有不需要的扇形的边 */
setcolor(2);
arc(350,250,0+i*30,30+i*30,210);
getarccoords(&arcinfo);
line(350,250,arcinfo.xend,arcinfo.yend);
}
setcolor(2);
setlinestyle(0,0,3);
circle(350,250,210);
for(i=4;i<200;i++){ /*去掉扇形的边 */
setcolor(0);
setlinestyle(0,0,3);
circle(350,250,i);
} /*去掉扇形的边 */
setcolor(6);
line(350,250,350,100); /*初始化分针*/
setcolor(8);
line(350,250,350,70); /*初始化时针*/
while(i>=0){
for(i=0;i<=60;i++){if(i==60)
{minute();j++;
if(j%60==0) hour();} /*控制针的转动*/
else {second(i);
}
}
}
getch();
restorecrtmode();
}