已生成时钟小程序链接:https://download.csdn.net/download/qq_31293403/86513976

#define _stprintf
#define _stprintf_s
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>
#include<string.h>
#include<tchar.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159
#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 b(a,b,c) X(a,b,c);Y(a,b,c);void Draw(int hour, int minute, int second)
{double a_hour, a_min, a_sec; // 时、分、秒针的弧度值int x_hour, y_hour, x_min, y_min, x_sec, y_sec; // 时、分、秒针的末端位置int x4, y4;// 计算时、分、秒针的弧度值a_sec = second * 2 * PI / 60;a_min = minute * 2 * PI / 60 + a_sec / 60; a_hour = hour * 2 * PI / 12 + a_min / 12;// 计算时、分、秒针的末端位置x_sec = 320 + (int)(120 * sin(a_sec));y_sec = 240 - (int)(120 * cos(a_sec));x_min = 320 + (int)(100 * sin(a_min));y_min = 240 - (int)(100 * cos(a_min));x_hour = 320 + (int)(70 * sin(a_hour));y_hour = 240 - (int)(70 * cos(a_hour));// 画时针setlinestyle(SOLID_FILL,2,0,10);setcolor(WHITE);line(320, 240, x_hour, y_hour);// 画分针setlinestyle(SOLID_FILL,2,0,6);setcolor(LIGHTGRAY);line(320, 240, x_min, y_min);// 画秒针setlinestyle(SOLID_FILL,2,0,2);setcolor(RED);line(320, 240, x_sec, y_sec);/*画十二时辰*/TCHAR s1[12];//分配用来保存十二时辰字符的指针数组x4 = 175 * sin(0.5 * PI / 180) + 316;y4 = 175 * -cos(0.5 * PI / 180) + 230;setcolor(LIGHTCYAN);_stprintf_s(s1, _T("子"));outtextxy(x4, y4, s1);x4 = 175 * sin(30 * PI / 180) + 316;y4 = 175 * -cos(30 * PI / 180) + 230;_stprintf_s(s1, _T("丑"));outtextxy(x4, y4, s1);x4 = 175 * sin(60 * PI / 180) + 316;y4 = 175 * -cos(60 * PI / 180) + 230;_stprintf_s(s1, _T("寅"));outtextxy(x4, y4, s1);x4 = 175 * sin(90 * PI / 180) + 316;y4 = 175 * -cos(90 * PI / 180) + 230;_stprintf_s(s1, _T("卯"));outtextxy(x4, y4, s1);x4 = 175 * sin(120 * PI / 180) + 316;y4 = 175 * -cos(120 * PI / 180) + 230;_stprintf_s(s1, _T("辰"));outtextxy(x4, y4, s1);x4 = 175 * sin(150 * PI / 180) + 316;y4 = 175 * -cos(150 * PI / 180) + 230;_stprintf_s(s1, _T("巳"));outtextxy(x4, y4, s1);x4 = 175 * sin(180 * PI / 180) + 316;y4 = 175 * -cos(180 * PI / 180) + 230;_stprintf_s(s1, _T("午"));outtextxy(x4, y4, s1);x4 = 175 * sin(210 * PI / 180) + 316;y4 = 175 * -cos(210 * PI / 180) + 230;_stprintf_s(s1, _T("未"));outtextxy(x4, y4, s1);x4 = 175 * sin(240 * PI / 180) + 316;y4 = 175 * -cos(240 * PI / 180) + 230;_stprintf_s(s1, _T("申"));outtextxy(x4, y4, s1);x4 = 175 * sin(270 * PI / 180) + 316;y4 = 175 * -cos(270 * PI / 180) + 230;_stprintf_s(s1, _T("酉"));outtextxy(x4, y4, s1);x4 = 175 * sin(300 * PI / 180) + 316;y4 = 175 * -cos(300 * PI / 180) + 230;_stprintf_s(s1, _T("戌"));outtextxy(x4, y4, s1);x4 = 175 * sin(330 * PI / 180) + 316;y4 = 175 * -cos(330 * PI / 180) + 230;_stprintf_s(s1, _T("亥"));outtextxy(x4, y4, s1);/*绘制八卦字符*/TCHAR s2[8];x4 = 202 * sin(0.5 * PI / 180) + 316;y4 = 202 * -cos(0.5 * PI / 180) + 230;_stprintf_s(s2, _T("坎"));outtextxy(x4, y4, s2);x4 = 202 * sin(45 * PI / 180) + 316;y4 = 202 * -cos(45 * PI / 180) + 230;_stprintf_s(s2, _T("艮"));outtextxy(x4, y4, s2);x4 = 202 * sin(90 * PI / 180) + 316;y4 = 202 * -cos(90 * PI / 180) + 230;_stprintf_s(s2, _T("震"));outtextxy(x4, y4, s2);x4 = 202 * sin(135 * PI / 180) + 316;y4 = 202 * -cos(135 * PI / 180) + 230;_stprintf_s(s2, _T("巽"));outtextxy(x4, y4, s2);x4 = 202 * sin(180 * PI / 180) + 316;y4 = 202 * -cos(180 * PI / 180) + 230;_stprintf_s(s2, _T("离"));outtextxy(x4, y4, s2);x4 = 202 * sin(225 * PI / 180) + 316;y4 = 202 * -cos(225 * PI / 180) + 230;_stprintf_s(s2, _T("坤"));outtextxy(x4, y4, s2);x4 = 202 * sin(270 * PI / 180) + 316;y4 = 202 * -cos(270 * PI / 180) + 230;_stprintf_s(s2, _T("兑"));outtextxy(x4, y4, s2);x4 = 202 * sin(315 * PI / 180) + 316;y4 = 202 * -cos(315 * PI / 180) + 230;_stprintf_s(s2, _T("乾"));outtextxy(x4, y4, s2);
}int main()
{int i, j, k, l, m, x1, x2, y1, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7;initgraph(650, 500, 0);/*绘制罗盘*/setcolor(LIGHTGREEN);circle(320, 240, 4);//指针中心点circle(320, 240, 160);//数字时钟圆circle(320, 240, 190);//十二时辰圆circle(320, 240, 220);//八卦圆for (i = 0; i < 60; i++) /*绘数字钟刻度*/{if (i % 5 == 0) {l = 15;}else {l = 5;}x1 = 160 * sin(i * 6 * PI / 180) + 320;y1 = 160 * cos(i * 6 * PI / 180) + 240;x2 = (160 - l)*sin(i * 6 * PI / 180) + 320;y2 = (160 - l)*cos(i * 6 * PI / 180) + 240;line(x1, y1, x2, y2);}for (j = 0; j <= 12; j++)/*绘钟表数字*/{x3 = 136 * sin(j * 30 * PI / 180) + 316;y3 = 136 * -cos(j * 30 * PI / 180) + 230;setcolor(LIGHTCYAN);TCHAR s[12];_stprintf(s, _T("%d"), j);outtextxy(x3, y3, s);}for (k = 0; k < 12; k++)/*绘十二时辰刻度*/{l = 30;x4 = 190 * sin(k * 30 * PI / 180+6) + 320;y4 = 190 * cos(k * 30 * PI / 180+6) + 240;x5 = (190-l) * sin(k * 30 * PI / 180+6) + 320;y5 = (190-l) * cos(k * 30 * PI / 180+6) + 240;line(x4, y4, x5, y5);}for (m = 0; m < 9; m++)/*绘制八卦刻度*/{x6 = 220 * sin(m * 45 * PI / 180-2) + 320;y6 = 220 * cos(m * 45 * PI / 180-2) + 240;x7 = (220 - l)*sin(m * 45 * PI / 180-2) + 320;y7 = (220 - l)*cos(m * 45 * PI / 180-2) + 240;line(x6, y6, x7, y7);}setwritemode(R2_XORPEN); // 设置 XOR 绘图模式// 绘制表针SYSTEMTIME ti; // 定义变量保存当前时间while (!_kbhit())//按任意键退出{GetLocalTime(&ti);Draw(ti.wHour, ti.wMinute, ti.wSecond); // 画表针Sleep(1000); // 延时 1 秒Draw(ti.wHour, ti.wMinute, ti.wSecond); // 擦表针}closegraph();
}

此程序默认编译IDE(VS2017)——使用之前请将字符集模式设置为“宽字符字集”,否则会乱码!

八卦罗盘动态时钟(C语言)相关推荐

  1. 【JAVA 八卦罗盘动态运行实现】

    JAVA 八卦罗盘动态运行实现 使用JAVA 实现易经64卦动态选卦移动方案

  2. android n 动态时钟,基于JQuery的动态罗盘时钟

    基于JQuery的动态罗盘时钟, 惯例,先来效果图 Index.html 动态时钟 * { margin: 0; padding: 0; } body { background-attachment: ...

  3. 用 Python 画动态时钟

    文 | 闲欢 来源:Python 技术「ID: pythonall」 时钟是我们日常生活中最常见的也是必不可少的东西,你有没有想过用 Python 来画一个实时动态的时钟呢?下面我们来看看如何使用简单 ...

  4. CyberMiles发布动态可扩展语言Lity,它凭什么叫板Solidity?

    版权声明:本文为博主原创文章, 转自https://blog.csdn.net/Blockchain_lemon/article/details/81904699,未经博主允许不得转载. 第一次见 M ...

  5. CAD动态时钟(默认走五分钟)

    C语言实现的CAD动态时钟,默认走五分钟,利用C语言生成SCR文件,然后用AutoCAD2002加载SCR文件得到结果. 代码如下: #include<STDIO.H> #include& ...

  6. 教你制作 简易罗盘动态时钟 网页文件

    简易罗盘动态时钟(含html文件和源码) 快来获取 首先给大家展示成品截图 首选展示index.txt代码 <动态罗盘时钟> <!DOCTYPE html> <html ...

  7. c语言数码管数字时钟程序,数码管显示模拟8位时钟C语言程序设计

    原标题:数码管显示模拟8位时钟C语言程序设计 //数码时钟设计 #include // 包含寄存器定义的头文件 unsigned char Tab[ ]={0xc0,0xf9,0xa4,0xb0,0x ...

  8. 电子时钟单片机c语言程序,51单片机电子时钟C语言程序

    本程序基于ATM89系列单片机的电子时钟C语言程序,能显示月日时分秒,同时还能调节其值!显示方式用六个8段数码管! #include//头文件 #define uchar unsigned char/ ...

  9. javascript 计算器、动态时钟、表格复选框全选(扩展)、轮播图、36选7、随机数...

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. python动态时钟代码_python实现简易动态时钟

    本文实例为大家分享了python实现简易动态时钟的具体代码,供大家参考,具体内容如下 from turtle import * from datetime import * #移动到指定位置 def ...

最新文章

  1. linux 树莓派查看ip,树莓派 常用Linux命令
  2. 关于日期比较compareTo
  3. Codeforces 1159A A pile of stones
  4. shiro学习(12)No WebApplicationContext found:
  5. [Reinforcement Learning] Value Function Approximation
  6. 2021年软件开发的五大趋势,低代码/无代码得到了验证!
  7. 研究生英语单词学习——Learning English
  8. 网络疯传华为面试题:800公斤牛,过承重700公斤的桥,有答案了?
  9. ERP企业管理系统与CRM客户关系管理系统集成套路
  10. 【IT生活】成长,没有想象的那么迫切 ——叶绍琛
  11. 为什么python打不开_Python打不开.py文件
  12. vant 表单按钮置灰_Vant Switch 开关
  13. 实用网址(永久更新中)
  14. 阿里云服务器---修改下载源---阿里云镜像---yum--CentOS
  15. 深度解析:CPU与GPU有什么区别?xPU又是什么鬼?
  16. 课后作业4:个人总结
  17. 微服务入门到入土(07)-分布式搜索ElasticSearch
  18. 趣味数学--贷款计算
  19. 利用python可视化散点图及其计算欧式距离分析相关性
  20. JMeter开发一个最简单的Sampler

热门文章

  1. 51nod 牛奶 bfs深度优先搜索
  2. 牛客网在线编程Javascript输入输出
  3. 数字逻辑课程设计(一):数字时钟——logisam模拟实现
  4. perl中uc,lc,ucfirst,lcfirst的用法(转载)
  5. the JDBC Driver has been forcibly unregistered.
  6. 解决 invalid DSN: missing the slash separating the database name
  7. CTF-MISC基础-压缩包隐写总结
  8. HDAO one error
  9. 苹果手机怎么投屏王者荣耀
  10. Windows 32位程序内存扩展