Skip to content

Commit 95d57cb

Browse files
authored
Add files via upload
1 parent cb629dc commit 95d57cb

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

blog27-opencv/blog27-04.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
from OpenGL.GL import *
3+
from OpenGL.GLU import *
4+
from OpenGL.GLUT import *
5+
import math
6+
import time
7+
8+
h = 0
9+
m = 0
10+
s = 0
11+
12+
# 绘制图像函数
13+
def Draw():
14+
PI = 3.1415926
15+
R = 0.5
16+
TR = R - 0.05
17+
glClear(GL_COLOR_BUFFER_BIT)
18+
glLineWidth(5)
19+
glBegin(GL_LINE_LOOP)
20+
for i in range(100):
21+
glVertex2f(R * math.cos(2 * PI / 100 * i), R * math.sin(2 * PI / 100 * i))
22+
glEnd()
23+
glLineWidth(2)
24+
for i in range(100):
25+
glBegin(GL_LINES)
26+
glVertex2f(TR * math.sin(2 * PI / 12 * i), TR * math.cos(2 * PI / 12 * i))
27+
glVertex2f(R * math.sin(2 * PI / 12 * i), R * math.cos(2 * PI / 12 * i))
28+
glEnd()
29+
glLineWidth(1)
30+
31+
h_Length = 0.2
32+
m_Length = 0.3
33+
s_Length = 0.4
34+
count = 60.0
35+
s_Angle = s / count
36+
count *= 60
37+
m_Angle = (m * 60 + s) / count
38+
count *= 12
39+
h_Angle = (h * 60 * 60 + m * 60 + s) / count
40+
glLineWidth(1)
41+
glBegin(GL_LINES)
42+
glVertex2f(0.0, 0.0)
43+
glVertex2f(s_Length * math.sin(2 * PI * s_Angle), s_Length * math.cos(2 * PI * s_Angle))
44+
glEnd()
45+
glLineWidth(5)
46+
glBegin(GL_LINES)
47+
glVertex2f(0.0, 0.0)
48+
glVertex2f(h_Length * math.sin(2 * PI * h_Angle), h_Length * math.cos(2 * PI * h_Angle))
49+
glEnd()
50+
glLineWidth(3)
51+
glBegin(GL_LINES)
52+
glVertex2f(0.0, 0.0)
53+
glVertex2f(m_Length * math.sin(2 * PI * m_Angle), m_Length * math.cos(2 * PI * m_Angle))
54+
glEnd()
55+
glLineWidth(1)
56+
glBegin(GL_POLYGON)
57+
for i in range(100):
58+
glVertex2f(0.03 * math.cos(2 * PI / 100 * i), 0.03 * math.sin(2 * PI / 100 * i));
59+
glEnd()
60+
glFlush()
61+
62+
# 更新时间函数
63+
def Update():
64+
global h, m, s
65+
t = time.localtime(time.time())
66+
h = int(time.strftime('%H', t))
67+
m = int(time.strftime('%M', t))
68+
s = int(time.strftime('%S', t))
69+
glutPostRedisplay()
70+
71+
# 主函数
72+
if __name__ == "__main__":
73+
glutInit()
74+
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
75+
glutInitWindowSize(400, 400)
76+
glutCreateWindow("My clock")
77+
glutDisplayFunc(Draw)
78+
glutIdleFunc(Update)
79+
glutMainLoop()

0 commit comments

Comments
 (0)