On Sun, May 18, 2008 at 12:17 PM, Mike Lawrence <[EMAIL PROTECTED]> wrote: > > Hi all, > > Looks like I need some help with a *really* simple paintshop-like > program I'm coding. The code below implements painting with a circular > white brush, but it doesn't seem to update the cursor position quickly > enough to paint continuous strokes. Any suggestions? > > import pyglet > from pyglet import window, image > from pyglet.gl import * > from math import * > > win=window.Window(fullscreen=True) > > brush_size = 10 > > def draw_circle(x,y,diameter): > glBegin(GL_TRIANGLE_FAN) > glVertex2f(x, y) > for angle in range(361): > glVertex2f( x+sin(angle)*(diameter/2.0), > y+cos(angle)*(diameter/ > 2.0) ) > glEnd() > > def on_mouse_drag(x, y, dx, dy, buttons, modifiers): > glColor3f(1,1,1) > for i in range(2): > draw_circle(x,y,brush_size) > draw_circle(x-dx,y-dy,brush_size) > win.flip() > > win.on_mouse_drag = on_mouse_drag > > def on_mouse_press(x,y,buttons,modifiers): > for i in range(2): > draw_circle(x,y,brush_size) > win.flip() > > win.on_mouse_press=on_mouse_press > > while True: > win.dispatch_events()
There are two issues. 1. Your drawing code is very inefficient. Using a display list or an image to draw the brush shape with only a few GL calls will allow pyglet to receive more mouse events. 2. By default, operating systems don't actually sample the mouse position very often. You can confirm this diagnosis by using a tablet (typically sampled at 100Hz on consumer tablets). Applications like Photoshop and Gimp connect mouse points together with Bezier splines to create continuous brush strokes (Gimp only does this for the standard brushes... if you use a bitmap brush you will not get a continuous stroke). Alex. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to pyglet-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---