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;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值