-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-1.py
More file actions
75 lines (62 loc) · 1.97 KB
/
2-1.py
File metadata and controls
75 lines (62 loc) · 1.97 KB
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
import glfw
from OpenGL.GL import*
import numpy as np
ptype = GL_LINE_LOOP
vertexs = None
def KeyCallback(window, key, scancode, action, mods):
global ptype
if key == glfw.KEY_1 and action == glfw.PRESS:
ptype = GL_POINTS
elif key == glfw.KEY_2 and action == glfw.PRESS:
ptype = GL_LINES
elif key == glfw.KEY_3 and action == glfw.PRESS:
ptype = GL_LINE_STRIP
elif key == glfw.KEY_4 and action == glfw.PRESS:
ptype = GL_LINE_LOOP
elif key == glfw.KEY_5 and action == glfw.PRESS:
ptype = GL_TRIANGLES
elif key == glfw.KEY_6 and action == glfw.PRESS:
ptype = GL_TRIANGLE_STRIP
elif key == glfw.KEY_7 and action == glfw.PRESS:
ptype = GL_TRIANGLE_FAN
elif key == glfw.KEY_8 and action == glfw.PRESS:
ptype = GL_QUADS
elif key == glfw.KEY_9 and action == glfw.PRESS:
ptype = GL_QUAD_STRIP
elif key == glfw.KEY_0 and action == glfw.PRESS:
ptype = GL_POLYGON
elif key == glfw.KEY_ESCAPE and action == glfw.PRESS:
glfw.set_window_should_close(window = window, value = glfw.TRUE)
def makeVertex():
global vertexs
a = np.linspace(0, np.pi*2, num=13)
vList = []
for th in a :
vList.append((np.cos(th),np.sin(th)))
vList.pop()
vertexs = np.array(vList)
def render():
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glBegin(ptype)
for vertex in vertexs:
glVertex2fv(vertex)
glEnd()
def main():
if not glfw.init():
return
window = glfw.create_window(480,480,"2021005923-2-1",None,None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
glfw.set_key_callback(window,KeyCallback)
glfw.swap_interval(1)
makeVertex()
while not glfw.window_should_close(window):
glfw.poll_events()
render()
glfw.swap_buffers(window)
glfw.terminate()
if __name__ == "__main__":
main()