import time, math from pyglet.gl import * window = pyglet.window.Window() class AlphaSquare: def __init__(self, moveradius, color): self.moveradius = moveradius self.xpos = 0 self.ypos = 0 self.color = color self.vlist = pyglet.graphics.vertex_list(4, ('v2f', [-128,-128, 128,-128, -128,128, 128,128])) 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) self.vlist.draw(GL_TRIANGLE_STRIP) 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(0, [1, 1, 1, 1]) ) objects.append( AlphaSquare(128, [1,0,0, 0.5]) ) @window.event def on_draw(): glClearColor(0, 0.3, 0.5, 0) glClear(GL_COLOR_BUFFER_BIT) glLoadIdentity() glTranslatef(320,240,0) for o in objects: o.draw() def update(dt): global objects for o in objects: o.update(dt) objects[1].color[3] = (1+math.sin(time.time()))/2.0 pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()