-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab1_example.py
68 lines (57 loc) · 1.74 KB
/
lab1_example.py
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
import glfw
from OpenGL.GL import *
delta = 0.1
angle = 0.0
posx = 0.0
posy = 0.0
size = 0.0
def main():
if not glfw.init():
return
window = glfw.create_window(640, 640, "Lab1", None, None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
glfw.set_key_callback(window, key_callback)
glfw.set_scroll_callback(window, scroll_callback)
while not glfw.window_should_close(window):
display(window)
glfw.destroy_window(window)
glfw.terminate()
def display(window):
global angle
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glClearColor(0.5, 0.25, 1.0, 1.0)
glPushMatrix()
glRotatef(angle, 0, 0, 1)
glBegin(GL_POLYGON)
glColor3f(0.1,0.1,0.1)
glVertex2f(posx + size + 0.5,posy + size + 0.5)
glColor3f(0.35,0.0,0.89)
glVertex2f(posx - size + -0.5,posy + size + 0.5)
glColor3f(0.0,1.0,1.0)
glVertex2f(posx - size + -0.5,posy - size + -0.5)
glColor3f(0.78,0.23,1.0)
glVertex2f(posx + size + 0.5,posy - size + -0.5)
glEnd()
glPopMatrix()
angle += delta
glfw.swap_buffers(window)
glfw.poll_events()
def key_callback(window, key, scancode, action, mods):
global delta
global angle
if action == glfw.PRESS:
if key == glfw.KEY_RIGHT:
delta = -3
if key == 263: # glfw.KEY_LEFT
delta = 3
def scroll_callback(window, xoffset, yoffset):
global size
if (xoffset > 0):
size -= yoffset/10
else:
size += yoffset/10
main()