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















本文转自terryli51CTO博客,原文链接: http://blog.51cto.com/terryli/520623,如需转载请自行联系原作者

相关文章
|
19天前
|
C语言
C语言:内存函数(memcpy memmove memset memcmp使用)
C语言:内存函数(memcpy memmove memset memcmp使用)
|
5天前
|
存储 编译器 C语言
C语言:字符函数 & 字符串函数 & 内存函数
C语言:字符函数 & 字符串函数 & 内存函数
12 2
|
13天前
|
缓存 安全 编译器
【C 言专栏】C 语言函数的高效编程技巧
【5月更文挑战第1天】本文探讨了C语言中函数的高效编程技巧,包括函数的定义与作用(如代码复用和提高可读性)、设计原则(单一职责和接口简洁)、参数传递方式(值传递、指针传递和引用传递)、返回值管理、调用约定、嵌套与递归调用,以及函数优化技巧和常见错误避免。掌握这些技巧能提升C语言代码的质量和效率。
【C 言专栏】C 语言函数的高效编程技巧
|
16天前
|
C语言
pta浙大版《C语言程序设计(第3版)》 习题6-4 使用函数输出指定范围内的Fibonacci数 (20分)
pta浙大版《C语言程序设计(第3版)》 习题6-4 使用函数输出指定范围内的Fibonacci数 (20分)
|
16天前
|
C语言
pta 浙大版《C语言程序设计(第3版)》题目集 习题6-6 使用函数输出一个整数的逆序数 (20分)
pta 浙大版《C语言程序设计(第3版)》题目集 习题6-6 使用函数输出一个整数的逆序数 (20分)
|
16天前
|
C语言
(浙大版《C语言程序设计(第3版)》 习题6-5 使用函数验证哥德巴赫猜想 (20分)
(浙大版《C语言程序设计(第3版)》 习题6-5 使用函数验证哥德巴赫猜想 (20分)
|
18天前
|
安全 C语言
【C语言】strcpy与strncpy函数的使用和模拟实现
【C语言】strcpy与strncpy函数的使用和模拟实现
5 0
|
18天前
|
C语言
【C语言】字符分类函数与字符转换函数
【C语言】字符分类函数与字符转换函数
10 1
|
18天前
|
程序员 编译器 C语言
C语言之函数与参数
C语言之函数与参数
8 0