import sys, time, math, os, random from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * def drawSolidObjects(): glPushMatrix() glRotatef(-90, 1, 0, 0) glColor4f(0.2, 1, 0.3, 1) gluDisk(quadric, 0, 10, 32, 1) glPopMatrix() glPushMatrix() glTranslatef(-3, 0, 0) glRotatef(-90, 1, 0, 0) glColor4f(0.6, 0.2, 0.1, 1) glutSolidCone(2, 4, 16, 1) glPopMatrix() glPushMatrix() glTranslatef(1, 0, -4) glRotatef(-90, 1, 0, 0) glColor4f(0.4, 0.2, 0.8, 1) glutSolidCone(2, 4, 16, 1) glPopMatrix() def draw(): glClearColor(0, 0.3, 0.5, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, 1, 0.1, 100) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotatef(10, 1, 0, 0) glTranslatef(0,-2,-10) drawSolidObjects() glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glLightfv(GL_LIGHT0, GL_DIFFUSE, [0,0,0, 0]) glPushMatrix() glTranslatef(0,1,0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # glColor4f(1, 1, 1, math.sin(time.time())/2.0 + 0.5) glMaterialfv(GL_FRONT, GL_DIFFUSE, [1, 1, 1, math.sin(time.time())/2.0 + 0.5]) glutSolidTeapot(1) glDisable(GL_BLEND) glPopMatrix() glDisable(GL_LIGHTING) glutSwapBuffers() def keyboard(key, x, y): if key == chr(27): sys.exit(0) def specialkey(key,x,y): pass def update(dummy): glutTimerFunc(16, update, 0) glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(700,700) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialkey) glutTimerFunc(1, update, 0) quadric = gluNewQuadric() glEnable(GL_DEPTH_TEST) glutMainLoop()