Drawing tons of circles in Python using cairo

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

Basically this application should draw simple moving shapes of different colors. I have a pretty complicated setup using pycairo that allows primitives to go through a set of modifiers to change position, scale, and rotation. This provides more flexibility.

Unfortunately, pycairo seems rather slow when drawing dotted circles. I tried drawing 30 circles:

# 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() 

It all looks like this . It is not capable of supporting 25 frames per second using 800x600 using Core2Duo.

Is there a faster way to draw circles? Quality is not a problem.

Thank you for your help!

+4
source share
1 answer

Cairo strives for high-quality rendering - it is used a lot in static or quasi-static rendering of 2d things.

Unsurprisingly, this can be slow - I think the first attempt I would make in your place is to use pygame + pyopenGL - I'm sorry that I am not ready with a complete example, but this project looks good: http: // www.willmcgugan.com/blog/tech/2007/6/4/opengl-sample-code-for-pygame/

+3
source

Source: https://habr.com/ru/post/1437837/


All Articles