import sys, math, time from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * def draw(): glClear(GL_COLOR_BUFFER_BIT) glColor3f(1,0,0) glBegin(GL_QUADS) glColor3fv([1,0,0]) glVertex2f(0, 0) glColor3f(0,0,1) glVertex2f(200, 20) glColor3f(1,0,0) glVertex2f(200, 300) glColor3f(1,0,1) glVertex2f(0, 300) glColor3ub(0,0,0xff) glVertex2f(150, 100) glVertex2f(400, 0) glVertex2f(400, 400) glVertex2f(300, 400) glEnd() glFlush() def reshape(w,h): glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, w, 0, h) glMatrixMode(GL_MODELVIEW) glutPostRedisplay() def keyboard(key, x, y): if key == chr(27): sys.exit(0) glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(500, 500) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutReshapeFunc(reshape) glutMainLoop()