import sys, math, time from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * x = 0 y = 0 direction = 0 def draw(): global x, y glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(x, y, 0.0) glRotatef(direction, 0.0, 0.0, 1.0) glRotatef(90, 0, 1, 0) glColor3f(1.0, 1.0, 0.0) glutWireCone(0.05, 0.1, 6, 1) glutSwapBuffers() def move(distance): global x,y, direction x += math.cos(direction * math.pi/180.0) * distance y += math.sin(direction * math.pi/180.0) * distance def keyboard(key, x, y): global quadric if key == chr(27): sys.exit(0) glutPostRedisplay() def specialkey(key,x,y): global direction if key == GLUT_KEY_LEFT: direction += 3 elif key == GLUT_KEY_RIGHT: direction -= 3 elif key == GLUT_KEY_UP: move(0.1) elif key == GLUT_KEY_DOWN: move(-0.1) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowSize(500,500) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialkey) glutMainLoop()