Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing tons of circles in Python using cairo

I am currently working on an application, which uses a video projector to create an effect similar to a real laser. A really nice example of what I'm trying to archive can be seen on Youtube here.

Basically that application needs to draw simple moving shapes in various colors. I have a pretty complicated setup using pycairo allowing the primitives to pass through a set of modifiers to change position, scale and rotation. This allows for a great deal of flexibility.

Unfortunately pycairo seems to be pretty slow at drawing dashed circles. I tried drawing 30 circles like this:

# setup, transforms...
# Example color-scheme:
self._colors = [(0.0, 1.0, 0.0)]
# drawing dashes one after another
for count, color in enumerate(self._colors):
    cr.set_dash(dash_len, self._dash_len * count)
    cr.set_source_rgb(color[0], color[1], color[2])

    cr.arc(0, 0, self.radius(), 0, 2 * math.pi)
    cr.stroke()

The whole thing looks like this. This is not able to sustain 25fps with on 800x600 using a Core2Duo.

Is there a faster way to draw circles? Quality is not really an issue.

Thanks for your help!

like image 884
Delphinator Avatar asked Oct 04 '12 15:10

Delphinator


1 Answers

Cairo aims at high-quality rendering - and it is used a lot in static, or quasi-static rendering of 2d things.

It is no wonder it can be slow -- I think the first try I'd make in your place would be to use pygame + pyopenGL -- I am sorry I am not comming with a full example, but this project looks like a good start: http://www.willmcgugan.com/blog/tech/2007/6/4/opengl-sample-code-for-pygame/

like image 103
jsbueno Avatar answered Oct 01 '22 02:10

jsbueno