欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

clock_1.c

这是一个用C语言做的模仿时钟走动的例子。实现了时分秒的走动
C
字号:
/* 小闹钟
   v 1.8
         02422班  第六小组制作
*/
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void windows()
{setcolor(5);
 rectangle(282,95,318,140);
 setfillstyle(5,15);
 bar(285,98,300,137);
 setfillstyle(4,15);
 bar(300,98,315,137);
}
void yantong()
{setfillstyle(7,5);
 bar(352,50,380,120);
}
void qiang()
{setcolor(11);
 setfillstyle(9,6);
 bar(200,145,400,160);
 bar(185,320,415,345);
 bar(200,145,220,320);
 bar(380,145,400,340);
}
void fanggai()
{int a,b,c;
 setcolor(11);
 for(a=b=c=0;a<130;a=b=++c)
 {line(290+a,60+a,325+b,60+b);
  line(310-a,60+a,275-b,60+b);
 }
}
void text()
{setcolor(2);
 settextstyle(1,0,5);
 outtextxy(350,400, "Alarum clock");
}
void init()
{int i,l,x1,x2,y1,y2;
 setbkcolor(1);
 setcolor(14);
 circle(300,240,2);
 setcolor(12);
 circle(300,240,3);
 setcolor(13);
 circle(300,240,4);
 setcolor(13);
 for(i=0;i<60;i++)
 {if(i%5==0) l=10;
  else l=5;
  x1=80*cos(i*6*pi/180)+300;
  y1=80*sin(i*6*pi/180)+240;
  x2=(80-l)*cos(i*6*pi/180)+300;
  y2=(80-l)*sin(i*6*pi/180)+240;
  line(x1,y1,x2,y2);
 }
}

main()
{int i=1,j,k=0,h1=0,m1=0;char c1,c;
 int x,y;
 int gd=VGA,gm=2;
 unsigned char h,m,s;
 struct time t[1];
 while(1)
 {clrscr();
  printf("\n\tDo you want to set alarum? Y,N\n\t");
  c=getch();
  if(c=='Y'||c=='y')
  {printf("hour:minute\n\t");
   scanf("%d:%d",&h1,&m1);
  }
  initgraph(&gd,&gm,"");
  init();
  text();
  windows();
  qiang();
  yantong();
  fanggai();
  setwritemode(1);
  gettime(t);
  h=t[0].ti_hour;
  m=t[0].ti_min;
  s=t[0].ti_sec;
  setcolor(7);
  d(57,(h*30+(k=m/12)*6),1);
  setcolor(14);
  d(66,m,6);
  setcolor(4);
  d(75,s,6);
  while(!kbhit())
  {while(t[0].ti_sec==s)
   gettime(t);
   for(j=0;j<1*i;j++)
   {sound(400*i/2);
    delay(70*i);
    sound(400*i/2);
    sound(80*i);
    delay(30*i);
   }
   nosound();
   setcolor(4);
   d(75,s,6);
   s=t[0].ti_sec;
   d(75,s,6);
   if(t[0].ti_min!=m)
   {setcolor(14);
    d(66,m,6);
    m=t[0].ti_min;
    d(66,m,6);
   }
   if(t[0].ti_hour!=h)
   {
    sound(1000);
    delay(240);
    nosound();
    delay(140);
    sound(800);
    delay(240);
    nosound();
   }
   if(t[0].ti_min%12==0&&t[0].ti_sec==0)
   {setcolor(7);
    d(57,(h*30+k*6),1);
    k=t[0].ti_min/12;
    h=t[0].ti_hour;
    d(57,(h*30+k*6),1);
   }
   if(h==h1&&m==m1) i=10;
   if(s==59) i=1;
  }
  getch();
  closegraph();
  printf("\n\tDo you want to close program ? Y,N");
  c1=getch();
  if(c1=='y'||c1=='Y') break;
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -