Created
September 24, 2013 12:46
-
-
Save davepape/6684176 to your computer and use it in GitHub Desktop.
animated transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyglet.gl import * | |
window = pyglet.window.Window(600,500) | |
triPosX = 10 | |
triPosY = 10 | |
triDX = 1 | |
triDY = 1 | |
triRot = 0 | |
triangle = pyglet.graphics.vertex_list(3, ('v2f', [-50,-50, 50,-50, 0,50])) | |
@window.event | |
def on_draw(): | |
glClear(GL_COLOR_BUFFER_BIT) | |
glLoadIdentity() | |
global triPosX, triPosY, triRot | |
glTranslatef(triPosX, triPosY, 0) | |
glRotatef(triRot, 0, 0, 1) | |
glColor3f(1, 0, 0.7) | |
triangle.draw(GL_TRIANGLES) | |
def update(dummy): | |
global triPosX, triPosY, triDX, triDY, triRot | |
if triPosX < 0: | |
triDX = 1 | |
elif triPosX > 600: | |
triDX = -1 | |
if triPosY < 0: | |
triDY = 1 | |
elif triPosY > 500: | |
triDY = -1 | |
triPosX += triDX * 5 | |
triPosY += triDY * 5 | |
triRot += 2 | |
pyglet.clock.schedule_interval(update,1/60.0) | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment