# Example for in-class assignment - clear a window to constantly changing color import sys, random from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * r,g,b = 0,0,0 dr, dg, db = 0.05, 0.07, 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) def update(v): glutTimerFunc(16, update, 0) global r,g,b,dr,dg,db r = r + dr g = g + dg b = b + db if r > 1: r = 0 if g > 1: g = 0 if b > 1: b = 0 glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(500, 500) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutTimerFunc(0, update, 0) glutMainLoop()