import sys, time, math from pyglet.gl import * from euclid import * window = pyglet.window.Window(512,512) quadric = gluNewQuadric() ballPos = Vector2(256,256) ballVel = Vector2(200,145) @window.event def on_draw(): glClear(GL_COLOR_BUFFER_BIT) glPushMatrix() glTranslatef(ballPos[0], ballPos[1], 0) glColor3f(1,0,0) gluDisk(quadric, 0, 20, 32, 1) glPopMatrix() def checkForBounce(): if ballPos[0] > 512.0: ballVel[0] = -ballVel[0] ballPos[0] = 512.0 - (ballPos[0] - 512.0) elif ballPos[0] < 0.0: ballVel[0] = -ballVel[0] ballPos[0] = -ballPos[0] if ballPos[1] > 512.0: ballVel[1] = -ballVel[1] ballPos[1] = 512.0 - (ballPos[1] - 512.0) elif ballPos[1] < 0.0: ballVel[1] = -ballVel[1] ballPos[1] = -ballPos[1] def update(dt): global ballPos, ballVel ballPos += ballVel * dt checkForBounce() pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()