-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-2.py
More file actions
60 lines (44 loc) · 1.1 KB
/
2-2.py
File metadata and controls
60 lines (44 loc) · 1.1 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
import glfw
from OpenGL.GL import *
import numpy as np
def render(T):
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
#draw coordinate
glBegin(GL_LINES)
glColor3ub(255,0,0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([1.,0.]))
glColor3ub(0,255,0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([0.,1.]))
glEnd()
#draw triangle
glBegin(GL_TRIANGLES)
glColor3ub(255,255,255)
glVertex2fv( (T @ np.array([.0,.5,1.])) [:-1] )
glVertex2fv( (T @ np.array([.0,.0,1.])) [:-1] )
glVertex2fv( (T @ np.array([.5,.0,1.])) [:-1] )
glEnd()
def main():
if not glfw.init():
return
window = glfw.create_window(480,480, "2021005923-2-2",None,None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
while not glfw.window_should_close(window):
glfw.poll_events()
t = glfw.get_time()
R=np.array([[np.cos(t), -np.sin(t), 0.0],
[np.sin(t), np.cos(t), 0.0],
[0.0,0.0,1.0]])
M=np.array([[1.,0.,.5],
[0.,1.,.1],
[0.,0.,1.]])
render(R@M);
glfw.swap_buffers(window)
glfw.terminate()
if __name__ =="__main__":
main()