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
| from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
from math import *
global anglex
anglex=0
def Paint(*args):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
p=[
[-0.5,-0.5, 0.5],
[-0.5, 0.5, 0.5],
[ 0.5, 0.5, 0.5],
[ 0.5,-0.5, 0.5],
[-0.5,-0.5,-0.5],
[-0.5, 0.5,-0.5],
[ 0.5, 0.5,-0.5],
[ 0.5,-0.5,-0.5]]
color=[
[1.0,1.0,1.0],
[0.5,0.5,0.5],
[0.0,0.5,1.0],
[0.0,0.0,1.0],
[0.5,0.0,1.0],
[1.0,0.0,1.0]]
f=(
(0,1,2,3),
(3,2,6,7),
(4,5,6,7),
(0,1,5,4),
(1,5,6,2),
(0,4,7,3));
for i in range(6):
glBegin(GL_POLYGON)
glColor3f(color[i][0], color[i][1], color[i][2])
for j in range(4):
glVertex3f(p[f[i][j]][0], p[f[i][j]][1], p[f[i][j]][2])
glEnd()
glFlush()
glutSwapBuffers()
def rotation(*args):
glLoadIdentity()
# La rotation se fait ICI
gluLookAt(cos((globals()['anglex']*3.14)/180),0, sin((globals()['anglex']*3.14)/180), 0,0,0, 0,1,0)
globals()['anglex']+=0.01
glFlush()
glutPostRedisplay()
glutSwapBuffers()
def reshape(x, y):
if (x<y):
glViewport(0,(y-x)/2,x,x);
else :
glViewport((x-y)/2,0,y,y)
def main(x, y):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE)
glutInitWindowSize(x, y)
glutCreateWindow('Carre Blanc')
glEnable(GL_DEPTH_TEST)
glutReshapeFunc(reshape)
glutDisplayFunc(Paint)
glutIdleFunc(rotation)
glutMainLoop()
main(300, 300) |
Partager