#include<graphics.h>
#include<iostream>
#include<cmath>
#include<ctime>
#define PI 3.141592653
using namespace std;
int gettime()
{
return clock()/CLOCKS_PER_SEC;
}
void plottime(int h,int m,int s)
{
moveto(200,200);
lineto(200+90*cos((90-s*6)*PI/180),200-90*sin((90-s*6)*PI/180));
moveto(200,200);
lineto(200+70*cos((90-m*6)*PI/180),200-70*sin((90-m*6)*PI/180));
moveto(200,200);
lineto(200+40*cos((90-h*30)*PI/180),200-40*sin((90-h*30)*PI/180));
}
void plotfigure()
{
int x,y;
char str[3];
circle(200,200,100);
for(int i=0;i<12;i++)
{
x=int(200+100*cos((90-i*30)*PI/180));
y=int(200-100*sin((90-i*30)*PI/180));
circle(x,y,3);
sprintf(str,"%d",i==0?12:i);
outtextxy(x,y,str);
}
}
int main()
{
time_t t;
int lasttime=0;
int nowtime=0;
tm *lotime;
initgraph(640,480);
plotfigure();
t=time(0);
lotime=localtime(&t);
plottime(lotime->tm_hour,lotime->tm_min,lotime->tm_sec);
while(1)
{
nowtime=gettime();
if(nowtime-lasttime>0)
{
t=time(0);
lotime=localtime(&t);
cleardevice();
plotfigure();
plottime(lotime->tm_hour,lotime->tm_min,lotime->tm_sec);
lasttime=nowtime;
}
}
getchar();
closegraph();
return 0;
}
C++利用graphics.h的钟表程序
最新推荐文章于 2020-12-02 09:15:04 发布