import sys from math import * from pyglet.gl import * window = pyglet.window.Window() class Circle: def __init__(self,radius,r,g,b,x=0,y=0): self.radius = radius self.r = r self.g = g self.b = b self.x = x self.y = y def draw(self): glColor3f(self.r,self.g,self.b) glPushMatrix() glTranslatef(self.x, self.y ,0) glBegin(GL_TRIANGLE_FAN) glVertex2f(0,0) for angle in range(0,370,10): x = self.radius * cos(radians(angle)) y = self.radius * sin(radians(angle)) glVertex2f(x,y) glEnd() glPopMatrix() c = Circle(50,1,0,0,300,300) info = pyglet.text.Label('Mouse: ',x=5,y=5) @window.event def on_draw(): global c, info glClear(GL_COLOR_BUFFER_BIT) c.draw() info.draw() @window.event def on_mouse_motion(x,y,dx,dy): global c, info c.x = x c.y = y info.text = 'Mouse: %d %d %d %d' % (x,y,dx,dy) @window.event def on_mouse_press(x,y,button,modifiers): global c if button == pyglet.window.mouse.LEFT: c.radius -= 5 elif button == pyglet.window.mouse.RIGHT: c.radius += 5 pyglet.app.run()