找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3954|回复: 4
收起左侧

利用c++做一个模拟时钟程序 供大家欣赏

[复制链接]
ID:285473 发表于 2019-3-6 22:24 | 显示全部楼层 |阅读模式
利用c++做一个模拟时钟
捕获.JPG 0.png
  1. #include <iostream>
  2. #include "graphics.h"
  3. #include <math.h>
  4. #include <time.h>
  5. #include <windows.h>

  6. #define x0 210.0
  7. #define y0 210.0
  8. #define r 200.0

  9. POINT pt[60],pt_s[60],pt_m[60],pt_h[60],pt1[60];

  10. using namespace std;
  11. int main()
  12. {
  13.     initgraph(800,800);                                 //设置界面大小
  14.     setfillcolor(0xffccff);
  15.     setcolor(0xffccff);

  16.     fillellipse(x0,y0,10,10);
  17.     int s=45,m,h,n=0;
  18.     while(n<60)
  19.     {
  20.         pt_s[s].x=x0+(int)((r-20)*cos((n-90)*3.1415926/30.0));
  21.         pt_s[s].y=y0+(int)((r-20)*sin((n-90)*3.1415926/30.0));
  22.          
  23.         pt_m[s].x=x0+(int)((r-50)*cos((n-90)*3.1415926/30.0));
  24.         pt_m[s].y=y0+(int)((r-50)*sin((n-90)*3.1415926/30.0));
  25.          
  26.         pt_h[s].x=x0+(int)((r-80)*cos((n-90)*3.1415926/30.0));
  27.         pt_h[s].y=y0+(int)((r-80)*sin((n-90)*3.1415926/30.0));
  28.          
  29.         pt[s].x=x0+(int)(r*cos((n-90)*3.1415926/30.0));
  30.         pt[s].y=y0+(int)(r*sin((n-90)*3.1415926/30.0));

  31.         fillellipse(pt[s].x,pt[s].y,2,2);
  32.         n++;
  33.         s++;
  34.         if(s>=60)
  35.         {
  36.             s=0;
  37.         }
  38.     }
  39.     for(int i=0;i<12;i++)
  40.     {
  41.         fillellipse(pt[i*5].x,pt[i*5].y,5,5);
  42.     }
  43.     int xs,ys,xm=-1,ym=-1,xh=-1,yh=-1;
  44.     while(1)
  45.     {
  46.         int n,m;
  47.         SYSTEMTIME st={0};
  48.         GetLocalTime(&st);
  49.         setcolor(0xffccff);
  50.         line(x0,y0,pt_s[st.wSecond].x,pt_s[st.wSecond].y);
  51.         xs=pt_s[st.wSecond].x;
  52.         ys=pt_s[st.wSecond].y;
  53.         if(pt_m[st.wMinute].x!=xm && pt_m[st.wMinute].y!=ym)
  54.         {
  55.             setcolor(0);
  56.             line(x0,y0,xm,ym);
  57.             xm=pt_m[st.wMinute].x;
  58.             ym=pt_m[st.wMinute].y;
  59.             setcolor(0xffccff);
  60.         }
  61.         line(x0,y0,pt_m[st.wMinute].x,pt_m[st.wMinute].y);
  62.         if(st.wHour>12)
  63.         {
  64.             n=st.wHour-12;
  65.         }
  66.         else
  67.         {
  68.             n=st.wHour;
  69.         }
  70.         m=(n*60+st.wMinute)/12;
  71.         line(x0,y0,pt_h[m].x,pt_h[m].y);
  72.         Sleep(1000);
  73.         setcolor(0x0);
  74.         line(x0,y0,xs,ys);
  75.         fillellipse(x0,y0,10,10);
  76.     }
  77.     closegraph();
  78.     return 0;
  79. }
复制代码

全部资料51hei下载地址:
c++模拟时钟.rar (586.3 KB, 下载次数: 33)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:285473 发表于 2019-3-6 22:27 | 显示全部楼层
不是C语言o
回复

使用道具 举报

ID:473159 发表于 2019-3-8 03:23 | 显示全部楼层
真不明白,我用C写的类似案例版主却不放进来
回复

使用道具 举报

ID:285473 发表于 2019-6-28 19:06 | 显示全部楼层
yoxi 发表于 2019-3-8 03:23
真不明白,我用C写的类似案例版主却不放进来

这是C++兄弟
回复

使用道具 举报

ID:574797 发表于 2019-6-29 22:23 来自手机 | 显示全部楼层
李清波8 发表于 2019-6-28 19:06
这是C++兄弟

谢谢分享!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表