-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3d.py
More file actions
96 lines (88 loc) · 1.58 KB
/
test3d.py
File metadata and controls
96 lines (88 loc) · 1.58 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pygame
import OpenGL
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices= (
(1, -1, -1),
(0,1,0),
(1,0,0),
(0,0,1),
(0,0,-1),
(-1,0,0),
(0,-1,0),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1),
(-1, -1, 1),
(-1, 1, 1),
#octahedron
)
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),
#octahedron
(8,10),
(8,12),
(8,11),
(8,13),
(9,10),
(9,12),
(9,11),
(9,13),
(10,12),
(10,13),
(11,12),
(11,13)
)
faces = (
(1,2,3),
(4,2,1),
(4,1,5),
(1,3,5),
(6,3,2),
(5,3,6),
(2,4,6),
(4,5,6)
)
def Cube():
color = 0
glBegin(GL_TRIANGLES)
for face in faces:
for vertex in face:
glColor3f(color,color+0.15,color+0.65)
glVertex3fv(vertices[vertex])
color = (color+0.1)%1
glEnd()
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50)
glTranslatef(0.0,0.0, -5)
glFrontFace(GL_CW)
glCullFace(GL_BACK)
glEnable(GL_CULL_FACE)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()