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