本文主要是介绍C语言写的一个钟表(很炫哦),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下面是源代码:
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926
#define x 320
#define y 240
int main()
{
int gdriver = DETECT,gmode,i,l;
float th_hour,th_min,th_sec,m,n,x1,y1,x2,y2;
struct time curtime;
initgraph(&gdriver,&gmode,"");
while(! kbhit())
{
for(i=0;i<60;i++)
{
if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*PI/180)+320;
y1=200*sin(i*6*PI/180)+240;
x2=(200-l)*cos(i*6*PI/180)+320;
y2=(200-l)*sin(i*6*PI/180)+240;
setcolor(2);
line(x1,y1,x2,y2);
}
gettime(&curtime);
/*得到当前系统时间*/
gotoxy(40,18); /*定位输出位置*/
setcolor(7);
outtextxy(getmaxx()/2-30,getmaxy()/4,"UESTC_TerryLi");
setcolor(2);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(20,20,getmaxx()-20,getmaxy()-20);
line(0,0,20,20);
line(getmaxx(),0,getmaxx()-20,20);
line(0,getmaxy(),20,getmaxy()-20);
line(getmaxx(),getmaxy(),getmaxx()-20,getmaxy()-20);
printf("Now Time:");
printf("%.0f:",(float)curtime.ti_hour);
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);
/*获得三个圆*/
circle(x,y,200);
circle(x,y,12);
setcolor(4); /*the first */
circle(x,y,3); /*the second */
setfillstyle(1,4); /*the third */
floodfill(x,y,4); /*fouth */ /*这四步画最中间的红圆*/
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 */
/*draw hour point*/
m = x + 90*sin(th_hour); /*70*/
n = y - 90*cos(th_hour);
setcolor(13);
line(x,y,m,n);
/*draw minute point*/ /*110*/
m = x + 130*sin(th_min);
n = y - 130*cos(th_min);
setcolor(11);
line(x,y,m,n);
/*draw second point*/ /*140*/
m = x + 170*sin(th_sec);
n = y - 170*cos(th_sec);
setcolor(5);
line(x,y,m,n);
sleep(1);
cleardevice();
}
closegraph();
return 0;
}
这篇关于C语言写的一个钟表(很炫哦)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!