# Simple program written in class, demonstrating idle-function import sys, math, time from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * frame = 0 size = 0.5 animating = False def draw(): global frame, size glClear(GL_COLOR_BUFFER_BIT) glutWireTeapot(size) glFlush() def keyboard(key, x, y): global animating if key == chr(27): sys.exit(0) elif key == 'a': animating = not animating startTime = time.time() def idle(): global frame, size, startTime frame = frame + 1 print time.time() - startTime if animating: size = math.sin(time.time()) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(200, 200) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutIdleFunc(idle) glutMainLoop()