C语言时钟表盘代码
时间: 2023-07-09 10:15:27 浏览: 110
以下是一个简单的 C 语言时钟表盘代码:
```
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<time.h>
#define PI 3.14159265
void main()
{
int gd=DETECT,gm,i;
int xmid,ymid,sec,min,hr;
double rsec,rmin,rhr;
struct tm *ptr;
time_t lt;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
xmid=getmaxx()/2;
ymid=getmaxy()/2;
settextstyle(0,0,3);
outtextxy(xmid-75,ymid-150,"ANALOG CLOCK");
circle(xmid,ymid,100);
for(i=1;i<=12;i++)
{
rsec=(i*(PI/6));
line(xmid+(90*cos(rsec)),ymid+(90*sin(rsec)),xmid+(100*cos(rsec)),ymid+(100*sin(rsec)));
}
while(!kbhit())
{
lt=time(NULL);
ptr=localtime(<);
sec=ptr->tm_sec;
min=ptr->tm_min;
hr=ptr->tm_hour;
rsec=(sec*(PI/30));
rmin=(min*(PI/30))+(sec*(PI/1800));
rhr=(hr*(PI/6))+(min*(PI/360))+(sec*(PI/21600));
line(xmid,ymid,xmid+(80*cos(rhr)),ymid+(80*sin(rhr)));
line(xmid,ymid,xmid+(90*cos(rmin)),ymid+(90*sin(rmin)));
line(xmid,ymid,xmid+(95*cos(rsec)),ymid+(95*sin(rsec)));
delay(1000);
cleardevice();
}
getch();
closegraph();
}
```
代码中使用了图形库 graphics.h,需要在编译环境中配置相应的库文件才能正常运行。
阅读全文