import time, math from pyglet.gl import * window = pyglet.window.Window() class Square: def __init__(self, color=[1,1,1]): self.color = color def draw(self): glColor3f(self.color[0],self.color[1],self.color[2]) glBegin(GL_TRIANGLE_STRIP) glVertex2f(-2,-2) glVertex2f(2,-2) glVertex2f(-2,2) glVertex2f(2,2) glEnd() def update(self,dt): pass class AlphaWheel: def __init__(self, moveradius=2.0, color=[1,1,1]): self.moveradius = moveradius self.color = color self.xpos = 0 self.ypos = 0 def draw(self): # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glPushMatrix() glTranslatef(self.xpos, self.ypos, 0) glBegin(GL_TRIANGLE_FAN) glColor4f(self.color[0],self.color[1],self.color[2],1) glVertex2f(0,0) glColor4f(self.color[0],self.color[1],self.color[2],0) for angle in range(0,361, 10): glVertex2f(math.sin(angle*math.pi/180.0)*2, math.cos(angle*math.pi/180.0)*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 = [ Square(), AlphaWheel(moveradius=2, color=[1,0,0]) ] @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): for o in objects: o.update(dt) pyglet.clock.schedule_interval(update,1/60.0) pyglet.app.run()