复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95#include<graphics.h> #include<conio.h> #include<math.h> #define high 480 //游戏画面尺寸 #define width 640 #define PI 3.14159 int main() { initgraph(width, high); //初始化绘图窗口 int center_x, center_y; //中心点坐标,钟表中心 center_x = width / 2; center_y = high / 2; int secondLength = width / 5; //秒针长度 int minuteLength = width / 6; //分针长度 int hourLength = width / 7; //时针长度 int secondEnd_x, secondEnd_y; //秒针重点 int minuteEnd_x, minuteEnd_y; //分针终点 int hourEnd_x, hourEnd_y; //时针终点 float secondAngle; //秒针对应角度 float minuteAngle; //分针对应角度 float hourAngle; //时针对应角度 SYSTEMTIME ti; //定义系统时间变量 BeginBatchDraw(); while (1) { //绘制表盘 setlinestyle(PS_SOLID, 1); setcolor(WHITE); circle(center_x, center_y, width / 4); //画刻度 int x, y, i; for (i = 0; i < 60; i++) { x = center_x + int(width / 4.3 * sin(PI * 2 * i / 60)); y = center_y + int(width / 4.3 * cos(PI * 2 * i / 60)); if (i % 15 == 0) bar(x - 5, y - 5, x + 5, y + 5); else if (i % 5 == 0) circle(x, y, 3); else putpixel(x, y, WHITE); } outtextxy(center_x - 25, center_y + width / 6, _T("我的时钟")); GetLocalTime(&ti); //获取当前时间 //秒针角度的变化 secondAngle = ti.wSecond * 2 * PI / 60; //分针角度变化 minuteAngle = ti.wMinute * 2 * PI / 60 + secondAngle / 60; //时针角度变化 hourAngle = ti.wHour * 2 * PI / 12 + minuteAngle / 12; //由角度决定的秒针短点坐标 secondEnd_x = center_x + secondLength * sin(secondAngle); secondEnd_y = center_y - secondLength * cos(secondAngle); //由角度决定分针端点坐标 minuteEnd_x = center_x + minuteLength * sin(minuteAngle); minuteEnd_y = center_y - minuteLength * cos(minuteAngle); //由角度决定的时针端点坐标 hourEnd_x = center_x + hourLength * sin(hourAngle); hourEnd_y = center_y - hourLength * cos(hourAngle); setlinestyle(PS_SOLID, 2); setcolor(YELLOW); line(center_x, center_y, secondEnd_x, secondEnd_y); //画秒针 setlinestyle(PS_SOLID, 4); setcolor(BLUE); line(center_x, center_y, minuteEnd_x, minuteEnd_y); //画分针 setlinestyle(PS_SOLID, 6); setcolor(RED); line(center_x, center_y, hourEnd_x, hourEnd_y); //画时针 FlushBatchDraw(); Sleep(10); setcolor(BLACK); setlinestyle(PS_SOLID, 3); line(center_x, center_y, secondEnd_x, secondEnd_y); setlinestyle(PS_SOLID, 5); line(center_x, center_y, minuteEnd_x, minuteEnd_y); setlinestyle(PS_SOLID, 10); line(center_x, center_y, hourEnd_x, hourEnd_y); } EndBatchDraw(); _getch(); //按任意键继续 closegraph(); //关闭绘图窗口 return 0; }
最后
以上就是成就芹菜最近收集整理的关于easyx时钟的全部内容,更多相关easyx时钟内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复