root / PyOpenGL-Demo / proesch / simple / simpleAnimation.py @ 2
Historique | Voir | Annoter | Télécharger (1,4 ko)
| 1 |
#!/usr/bin/python2.4
|
|---|---|
| 2 |
# Copyright (C) 2007 "Peter Roesch" <Peter.Roesch@fh-augsburg.de>
|
| 3 |
#
|
| 4 |
# This code is licensed under the PyOpenGL License.
|
| 5 |
# Details are given in the file license.txt included in this distribution.
|
| 6 |
|
| 7 |
import sys |
| 8 |
from time import sleep |
| 9 |
try:
|
| 10 |
from OpenGL.GLUT import * |
| 11 |
from OpenGL.GL import * |
| 12 |
from OpenGL.GLU import * |
| 13 |
except:
|
| 14 |
print ''' Error: PyOpenGL not installed properly !!''' |
| 15 |
sys.exit( ) |
| 16 |
|
| 17 |
animationAngle = 0.0
|
| 18 |
frameRate = 25
|
| 19 |
|
| 20 |
def doAnimationStep( ): |
| 21 |
"""Update animated parameters.
|
| 22 |
|
| 23 |
This Function is made active by glutSetIdleFunc"""
|
| 24 |
global animationAngle
|
| 25 |
global frameRate
|
| 26 |
animationAngle += 1
|
| 27 |
while animationAngle > 360: |
| 28 |
animationAngle -= 360
|
| 29 |
sleep( 1 / float( frameRate ) ) |
| 30 |
glutPostRedisplay( ) |
| 31 |
|
| 32 |
def display( ): |
| 33 |
"OpenGL display function""" |
| 34 |
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) |
| 35 |
glMatrixMode( GL_MODELVIEW ) |
| 36 |
glLoadIdentity( ) |
| 37 |
glColor3f( 1, 1, 1 ) |
| 38 |
glRotatef( animationAngle, 0, 0, 1 ) |
| 39 |
glBegin( GL_QUADS ) |
| 40 |
glVertex3f( -0.5, 0.5, 0 ) |
| 41 |
glVertex3f( -0.5, -0.5, 0 ) |
| 42 |
glVertex3f( 0.5, -0.5, 0 ) |
| 43 |
glVertex3f( 0.5, 0.5, 0 ) |
| 44 |
glEnd( ) |
| 45 |
glutSwapBuffers( ) |
| 46 |
|
| 47 |
def init( ): |
| 48 |
glClearColor ( 0, 0, 0, 0 ) |
| 49 |
glShadeModel( GL_SMOOTH ) |
| 50 |
|
| 51 |
glutInit( sys.argv ) |
| 52 |
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ) |
| 53 |
glutInitWindowSize( 250, 250 ) |
| 54 |
glutInitWindowPosition( 100, 100 ) |
| 55 |
glutCreateWindow( sys.argv[0] )
|
| 56 |
init( ) |
| 57 |
glutDisplayFunc( display ) |
| 58 |
glutIdleFunc( doAnimationStep ) |
| 59 |
glutMainLoop( ) |