<div>And instead of busylooping in rendering with</div><div><br></div><div> gobject.idle_add(timeout)</div><div><br></div><div>you could limit the framerate to eg. maximum of 60fps with</div><div><br></div><div> gobject.timeout_add(1000/60, timeout)</div>
<div><br></div><div>Much smoother that way ;)</div><div><br></div><div> Kalle</div><br><div class="gmail_quote">2010/1/31 Rye Terrell <span dir="ltr"><<a href="mailto:ryeterrell@ryeterrell.net">ryeterrell@ryeterrell.net</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Thank you; that is tremendously faster.<div><br></div><font color="#888888"><div>-Rye</div></font><div><div></div><div class="h5">
<div><br><div class="gmail_quote">On Sun, Jan 31, 2010 at 1:31 PM, Chris Wilson <span dir="ltr"><<a href="mailto:chris@chris-wilson.co.uk" target="_blank">chris@chris-wilson.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Sun, 31 Jan 2010 13:00:58 -0600, Rye Terrell <<a href="mailto:ryeterrell@ryeterrell.net" target="_blank">ryeterrell@ryeterrell.net</a>> wrote:<br>
> My program draws circles moving on the window. I think I must be missing<br>
> some basic gtk/cairo concept because it seems to be running too<br>
> slowly/stutteringly for what I am doing. Any ideas? Thanks for any help!<br>
<br>
</div>You happen to be drawing the same sprite 128 times, asking for full<br>
subpixel tessellation of the nigh on the saem geometry 384 times per<br>
expose. This is where a canvas and scenegraph are so valuable. But for<br>
this simple case:<br>
<div><br>
#!/usr/bin/env python<br>
<br>
import gtk<br>
import gtk.gdk as gdk<br>
import math<br>
import random<br>
import gobject<br>
<br>
# The number of circles and the window size.<br>
num = 128<br>
size = 512<br>
<br>
# Initialize circle coordinates and velocities.<br>
x = []<br>
y = []<br>
xv = []<br>
yv = []<br>
for i in range(num):<br>
x.append(random.randint(0, size))<br>
y.append(random.randint(0, size))<br>
xv.append(random.randint(-4, 4))<br>
yv.append(random.randint(-4, 4))<br>
<br>
<br>
# Draw the circles and update their positions.<br>
def expose(*args):<br>
</div> r = 8<br>
lw = 4<br>
c = int (r + (lw+1)/2 + 1)<br>
<div><br>
cr = darea.window.cairo_create()<br>
</div> cr.rectangle(0, 0, 2*c, 2*c)<br>
cr.clip()<br>
cr.push_group()<br>
<br>
# draw the circle sprite<br>
cr.set_line_width(lw)<br>
<div> cr.set_source_rgb(1, 0, 0)<br>
</div> cr.arc(c, c, r, 0, 2 * math.pi)<br>
<div> cr.stroke_preserve()<br>
cr.set_source_rgb(1, 1, 1)<br>
cr.fill()<br>
<br>
</div> p = cr.pop_group()<br>
cr.reset_clip()<br>
<div><br>
for i in range(num):<br>
</div> cr.save()<br>
cr.translate(x[i] - c, y[i] - c)<br>
cr.set_source(p)<br>
cr.paint()<br>
cr.restore()<br>
<div><div></div><div><br>
x[i] += xv[i]<br>
y[i] += yv[i]<br>
if x[i] > size or x[i] < 0:<br>
xv[i] = -xv[i]<br>
if y[i] > size or y[i] < 0:<br>
yv[i] = -yv[i]<br>
<br>
# Self-evident?<br>
def timeout():<br>
darea.queue_draw()<br>
return True<br>
<br>
# Initialize the window.<br>
window = gtk.Window()<br>
window.resize(size, size)<br>
window.connect("destroy", gtk.main_quit)<br>
darea = gtk.DrawingArea()<br>
darea.connect("expose-event", expose)<br>
window.add(darea)<br>
window.show_all()<br>
<br>
# Self-evident?<br>
gobject.idle_add(timeout)<br>
gtk.main()<br>
<br>
</div></div><font color="#888888">--<br>
Chris Wilson, Intel Open Source Technology Centre<br>
</font></blockquote></div><br></div>
</div></div><br>--<br>
cairo mailing list<br>
<a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
<a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br></blockquote></div><br><br clear="all"><br>-- <br>Kalle Vahlman, <a href="mailto:zuh@iki.fi">zuh@iki.fi</a><br>
Powered by <a href="http://movial.com">http://movial.com</a><br>Interesting stuff at <a href="http://sandbox.movial.com">http://sandbox.movial.com</a><br>See also <a href="http://syslog.movial.fi">http://syslog.movial.fi</a><br>
<br>