import sys, time, math from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * startTime = time.time() def drawObjects(): glColor3f(0, 0.5, 0) glBegin(GL_QUADS) glVertex3f(-100, -3, -100) glVertex3f(100, -3, -100) glVertex3f(100, -3, 100) glVertex3f(-100, -3, 100) glEnd() glColor3f(0, 0, 1) glPushMatrix() glTranslatef(0, -3, -5) glRotatef(-90, 1, 0, 0) glutWireCone(1, 5, 8, 1) glPopMatrix() glColor3f(0.8, 0, 0.3) glPushMatrix() glTranslatef(-10, -3, -20) glRotatef(-90, 1, 0, 0) glutWireCone(1, 5, 8, 1) glPopMatrix() glColor3f(0.5, 0.3, 0.7) glPushMatrix() glTranslatef(10, -3, -10) glRotatef(-90, 1, 0, 0) glutWireCone(1, 5, 8, 1) glPopMatrix() glColor3f(1.0, 0.0, 0.0) glPushMatrix() glTranslatef(30, 0, -5) glRotatef((time.time()-startTime)*30, 1, 1, 1) glutWireDodecahedron() glPopMatrix() glColor3f(1.0, 1.0, 0.0) glPushMatrix() glTranslatef(-20, math.sin(time.time())+1, 3) glutWireCube(4) glPopMatrix() glColor3f(0.2, 0.7, 0.4) glPushMatrix() glTranslatef(2, 0, 25) glutWireTeapot(3) glPopMatrix() def draw(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60, 1, 0.1, 1000) glMatrixMode(GL_MODELVIEW) drawObjects() glutSwapBuffers() def keyboard(key, x, y): if key == chr(27): sys.exit(0) def specialKey(key, x, y): pass def mousemotion(x,y): pass def update(x): glutTimerFunc(16, update, 0) glutPostRedisplay() glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(600, 600) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialKey) glutPassiveMotionFunc(mousemotion) glutTimerFunc(0, update, 0) glEnable(GL_DEPTH_TEST) glLineWidth(2) glutMainLoop()