# This program rotates a triangle about its center, rather than about # the world origin, by using two translations around the rotation. import sys from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * def draw(): glLoadIdentity() glClear(GL_COLOR_BUFFER_BIT) glColor3f(0, 0, 1) glBegin(GL_TRIANGLES) glVertex2f(0.5, 0.0) glVertex2f(0.8, 0.0) glVertex2f(0.65, 0.5) glEnd() glTranslatef(0.65, 0.25, 0.0) glRotatef(45, 0, 0, 1) glTranslatef(-0.65, -0.25, 0.0) glColor3f(0, 1, 0) glBegin(GL_TRIANGLES) glVertex2f(0.5, 0.0) glVertex2f(0.8, 0.0) glVertex2f(0.65, 0.5) glEnd() glFlush() def keyboard(key, x, y): if key == chr(27): sys.exit(0) glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(300, 300) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutMainLoop()