/*看了上面以为兄弟的钟表觉得比较简陋,且屏幕刷新闪烁严重,鼓作了一些改进,还请各位大侠指教*/
/*本程序已在TC3下调试过*/
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#define PI 3.1415926
#define x0 320 /*定义钟表中心坐标*/
#define y0 240
#define r 200
void DrawClock()
{
setcolor(4);
circle(x0,y0,210);
setcolor(9);
circle(x0,y0,215);
setcolor(5);
setfillstyle(1,5);
circle(x0,y0,10);
floodfill(x0,y0,5); /*画中间小圆并填充*/
}
void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}
void main()
{int i;
struct time curtime;
float th_hour,th_min,th_sec;
float th_hour_l,th_min_l,th_sec_l;
int graphdriver,graphmode;
graphdriver=DETECT;
initgraph(&graphdriver,&graphmode,"c:\\tc3\\7\\BGI ");//目录根据具体情况需做点改动
cleardevice();
char n[12][3]={"3","2","1","12","11","10","9","8","7","6","5","4"};
while(! kbhit())
{
DrawClock();
setcolor(2);
settextstyle(4,0,5);
for(i=0;i<12;i++)
{ if(i!=3)
{outtextxy(x0+(r-14)*cos(PI/6*i)-10,y0-(r-14)*sin(PI/6*i)-26,n[i]);
line(x0+200*cos(PI/6*i),y0-200*sin(PI/6*i),
x0+210*cos(PI/6*i),y0-210*sin(PI/6*i));
}
else
{outtextxy(x0+(r-14)*cos(PI/6*i)-20,y0-(r-14)*sin(PI/6*i)-26,n[i]);
line(x0+200*cos(PI/6*i),y0-200*sin(PI/6*i),
x0+210*cos(PI/6*i),y0-210*sin(PI/6*i));
}
}
gettime(&curtime); /*得到当前系统时间*/
gotoxy(36,20); /*定位输出位置*/
if((float)curtime.ti_hour<=12) /*午前的处理*/
{
printf("AM ");
if((float)curtime.ti_hour<10) printf("0"); /*十点之前在小时数前加零*/
printf("%.0f:",(float)curtime.ti_hour);
}
if((float)curtime.ti_hour>12) /*午后的处理*/
{printf("PM ");
if((float)curtime.ti_hour-12<10) printf("0");
printf("%.0f:",(float)curtime.ti_hour-12);
}
if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);
/*以下三行计算表针转动角度,以竖直向上为起点,顺时针为正*/
th_sec_l=th_sec;
th_min_l=th_min;
th_hour_l=th_hour;
th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour_l,90,0); /*画时针*/
DrawHand(x0,y0,th_min_l,120,0); /*分针*/
DrawHand(x0,y0,th_sec_l,180,0); /*秒针*/
DrawHand(x0,y0,th_hour,90,2);
DrawHand(x0,y0,th_min,120,3);
DrawHand(x0,y0,th_sec,180,12);
sleep(1); /*延时一秒后刷新*/
}
closegraph();
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |