from pyglet.gl import * window = pyglet.window.Window() triPosX = 0 triPosY = 0 triDX = 1 triDY = 1 triRot = 0 @window.event def on_draw(): glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(-15, 15, -10, 10) glMatrixMode(GL_MODELVIEW) glLoadIdentity() global triPosX, triPosY, triRot glTranslatef(triPosX, triPosY, 0) glRotatef(triRot, 0, 0, 1) glColor3f(1, 0, 0.7) glBegin(GL_TRIANGLES) glVertex2f(-1.0, -1.0) glVertex2f(1.0, -1.0) glVertex2f(0.0, 1.0) glEnd() def update(dummy): global triPosX, triPosY, triDX, triDY, triRot if triPosX < -15: triDX = 1 elif triPosX > 15: triDX = -1 if triPosY < -10: triDY = 1 elif triPosY > 10: triDY = -1 triPosX += triDX * 0.2 triPosY += triDY * 0.2 triRot += 2 pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()