Created
September 26, 2013 15:02
-
-
Save davepape/6715445 to your computer and use it in GitHub Desktop.
mouse input with pyglet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.r = r | |
self.g = g | |
self.b = b | |
self.x = x | |
self.y = y | |
self.size = 1 | |
verts = [0,0] | |
for angle in range(0,370,10): | |
x = radius * cos(radians(angle)) | |
y = radius * sin(radians(angle)) | |
verts = verts + [x,y] | |
self.vlist = pyglet.graphics.vertex_list(len(verts)/2, ('v2f',verts)) | |
def draw(self): | |
glColor3f(self.r,self.g,self.b) | |
glPushMatrix() | |
glTranslatef(self.x, self.y ,0) | |
glScalef(self.size, self.size, self.size) | |
self.vlist.draw(GL_TRIANGLE_FAN) | |
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.size = c.size * 0.9 | |
elif button == pyglet.window.mouse.RIGHT: | |
c.size = c.size * 1.1 | |
pyglet.app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment