import sys, math, time, string from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * delay = 0 x = 0 y = 0 quadric = 0 def draw(): glClear(GL_COLOR_BUFFER_BIT) global x,y, quadric glLoadIdentity() glColor3f(1,1,1) glRasterPos2f(0,-20) drawBitmapString('Delay: %d' % (delay)) glTranslatef(x, y, 0) glColor3f(1, 1, 0) gluDisk(quadric, 0, 10, 6, 6) glutSwapBuffers() def drawBitmapString(text, font=GLUT_BITMAP_TIMES_ROMAN_24): for c in text: glutBitmapCharacter(font, ord(c)) def reshape(width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, width, -height, 0) glMatrixMode(GL_MODELVIEW) def keyboard(key, x, y): if key == chr(27): sys.exit(0) def specialKey(key, x, y): global delay if key == GLUT_KEY_UP: delay += 10 elif key == GLUT_KEY_DOWN: if delay >= 10: delay -= 10 glutPostRedisplay() def callDraw(i): global x,y x = i % 10000 y = -i / 10000 draw() def mousemotion(mx,my): global delay glutTimerFunc(delay, callDraw, mx + my*10000) glutInit(sys.argv) if len(sys.argv) > 1: delay = string.atof(sys.argv[1]) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(400, 400) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialKey) glutPassiveMotionFunc(mousemotion) glutReshapeFunc(reshape) quadric = gluNewQuadric() reshape(400,400) glutMainLoop()