import sys from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * def draw(): glClear(GL_COLOR_BUFFER_BIT) glLoadIdentity() glColor3f(1,0,0) glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) glVertex2f(0.2, 0.0) glVertex2f(0.4, 0.4) glEnd() glColor3f(0,1,0) glTranslatef(0.4,0.4,0) glRotatef(45, 0, 0, 1) glTranslatef(-0.4,-0.4,0) glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) glVertex2f(0.2, 0.0) glVertex2f(0.4, 0.4) glEnd() glLoadIdentity() glFlush() def keyboard(key, x, y): if key == chr(27): sys.exit(0) glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(400, 400) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutMainLoop()