My program draws circles moving on the window. I think I must be missing some basic gtk/cairo concept because it seems to be running too slowly/stutteringly for what I am doing. Any ideas? Thanks for any help!<br><br><div>
<br><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">#!/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>    cr = darea.window.cairo_create()<br>    cr.set_line_width(4)<br>
    for i in range(num):<br>        cr.set_source_rgb(1, 0, 0)<br>        cr.arc(x[i], y[i], 8, 0, 2 * math.pi)<br>        cr.stroke_preserve()<br>        cr.set_source_rgb(1, 1, 1)<br>        cr.fill()<br>        x[i] += xv[i]<br>
        y[i] += yv[i]<br>        if x[i] &gt; size or x[i] &lt; 0:<br>            xv[i] = -xv[i]<br>        if y[i] &gt; size or y[i] &lt; 0:<br>            yv[i] = -yv[i]<br><br><br># Self-evident?<br>def timeout():<br>    darea.queue_draw()<br>
    return True<br><br><br># Initialize the window.<br>window = gtk.Window()<br>window.resize(size, size)<br>window.connect(&quot;destroy&quot;, gtk.main_quit)<br>darea = gtk.DrawingArea()<br>darea.connect(&quot;expose-event&quot;, expose)<br>
window.add(darea)<br>window.show_all()<br><br><br># Self-evident?<br>gobject.idle_add(timeout)<br>gtk.main()</font></div>