-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab1.py
98 lines (90 loc) · 1.93 KB
/
lab1.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
colors = (
(1, 0, 0),
(0, 0, 0),
(0, 0, 1),
(0, 1, 0),
(1, 1, 1),
(0, 1, 1),
(1, 0, 0),
(0, 1, 0),
(0, 0, 1),
(1, 0, 0),
(1, 1, 1),
(0, 1, 1),
)
surfaces = (
(0, 1, 2, 3),
(3, 2, 7, 6),
(6, 7, 5, 4),
(4, 5, 1, 0),
(1, 5, 7, 2),
(4, 0, 3, 6)
)
verticies = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1)
)
edges = (
(0, 1),
(0, 3),
(0, 4),
(2, 1),
(2, 3),
(2, 7),
(6, 3),
(6, 4),
(6, 7),
(5, 1),
(5, 4),
(5, 7)
)
def Cube():
glBegin(GL_QUADS)
for surface in surfaces:
x = 0
for vertex in surface:
x += 1
glColor3fv(colors[x])
glVertex3fv(verticies[vertex])
glEnd()
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
Cube()
pygame.display.flip()
while 1:
for i in pygame.event.get():
if i.type == pygame.QUIT:
quit()
elif i.type == pygame.KEYDOWN:
if i.key == pygame.K_LEFT:
glRotatef(-45, 0, 1, 1)
elif i.key == pygame.K_RIGHT:
glRotatef(45, 0, 1, 1)
elif i.key == pygame.K_UP:
glRotatef(-45, 1, 0, 1)
elif i.key == pygame.K_DOWN:
glRotatef(45, 1, 0, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
# pygame.time.wait(10)
main()