import time, math from pyglet.gl import * window = pyglet.window.Window() class AlphaSquare: def __init__(self, moveradius=0.0, color=[1,1,1,1]): self.moveradius = moveradius self.xpos = 0 self.ypos = 0 self.color = color def draw(self): glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glColor4f(self.color[0],self.color[1],self.color[2],self.color[3]) glPushMatrix() glTranslatef(self.xpos, self.ypos, 0) glBegin(GL_TRIANGLE_STRIP) glVertex2f(-2,-2) glVertex2f(2,-2) glVertex2f(-2,2) glVertex2f(2,2) glEnd() glPopMatrix() glDisable(GL_BLEND) def update(self,dt): self.xpos = self.moveradius * math.sin(time.time()) self.ypos = self.moveradius * math.cos(time.time()) objects = [] objects.append( AlphaSquare(color=[1, 1, 1, 1]) ) objects.append( AlphaSquare(moveradius=2, color=[1,0,0, 0.5]) ) @window.event def on_draw(): glClearColor(0, 0.3, 0.5, 0) glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(-5, 5, -5, 5) glMatrixMode(GL_MODELVIEW) for o in objects: o.draw() def update(dt): global objects for o in objects: o.update(dt) pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()