-
Notifications
You must be signed in to change notification settings - Fork 1
/
sphere.py
executable file
·84 lines (63 loc) · 1.59 KB
/
sphere.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
#!/usr/bin/env python
from pyglet import window
from pyglet.gl import *
from time import sleep
def myinit():
glClearColor(0.0, 0.0, 0.0, 0.0)
global q
q = gluNewQuadric();
glEnable(GL_DEPTH_TEST)
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE)
#glPolygonMode( GL_FRONT_AND_BACK, GL_FILL)
def myresize(width, height):
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1.0*width/height, 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
def mydisplay():
global t
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
gluLookAt(0.0, 2.0, 4.0, # eye
0.0, 0.0, -1.0, # center
0.0, 1.0, 0.0) # up
# glPushMatrix()
#glRotatef((3*t) % 360,0,1,0)
glColor3f(0, 1, 1)
gluSphere(q, 0.4, 20, 12)
glRotatef((3*t) % 360,0,1,0)
glTranslatef(1.5, 0, 0)
glColor3f(1, 0, 0)
gluSphere(q, 0.3, 18, 12)
"""
glRotatef(t % 360,0,1,0)
glPushMatrix()
glRotatef((10 * t) % 360,0,1,0)
glTranslatef(0.6,0,0)
glColor3f(1,1,0)
gluSphere(q,0.2,50,50)
glPopMatrix()
glPushMatrix()
glRotatef(30,0,0,1)
glRotatef((16 * t) % 360,0,1,0)
glTranslatef(0.8,0,0)
glColor3f(1,0,1)
gluSphere(q,0.15,50,50)
glPopMatrix()
"""
def main():
win = window.Window()
win.on_resize = myresize
myinit()
global t
t = 0.0
speed = 0.5
while not win.has_exit:
win.dispatch_events()
mydisplay()
win.flip()
t += speed
sleep(0.01)
if __name__ == "__main__":
main()