-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.py
More file actions
81 lines (68 loc) · 1.92 KB
/
lab1.py
File metadata and controls
81 lines (68 loc) · 1.92 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
76
77
78
79
80
81
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(1.0, 1.0, 1.0, 1.0)
glPushMatrix()
glRotatef(angle, 0, 0, 1)
glBegin(GL_POLYGON)
glColor3f(0.1,0.1,0.1)
glVertex2f(posx + size + 0.0,posy + size + 0.5)
glColor3f(0.78,0.23,1.0)
glVertex2f(posx - size + -0.5,posy + size + 0.0)
glColor3f(0.78,0.23,1.0)
glVertex2f(posx - size + -1.0,posy + size + 0.0)
glColor3f(0.0,1.0,1.0)
glVertex2f(posx - size + -0.25,posy - size + -0.25)
glColor3f(0.78,0.23,1.0)
glVertex2f(posx - size + -0.75,posy - size + -0.25)
glColor3f(0.78,0.23,1.0)
glVertex2f(posx + size + 0.75,posy - size + -0.25)
glColor3f(0.0,1.0,1.0)
glVertex2f(posx + size + 1.0,posy + size + 0.0)
glColor3f(0.35,0.0,0.89)
glVertex2f(posx + size + 0.5,posy + size + 0.0)
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 == 257:
delta = -0.01
if key == 32: # glfw.KEY_LEFT
delta = 0.01
if key == 344: # glfw.KEY_LEFT
delta = 1
def scroll_callback(window, xoffset, yoffset):
global size
if (xoffset > 0):
size -= yoffset/10
else:
size += yoffset/10
main()