# Example for in-class assignment - clear a window to different colors as keys are pressed import sys, random from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * r,g,b = 0,0,0 def draw(): glClearColor(r,g,b,0) glClear(GL_COLOR_BUFFER_BIT) glFlush() def keyboard(key, x, y): if key == chr(27): sys.exit(0) else: global r,g,b r,g,b = random.uniform(0,1), random.uniform(0,1), random.uniform(0,1) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(500, 500) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutMainLoop()