1

I recently had an itch to write a simple Mandelbrot set generator. I needed something that would allow me to output some graphics and manipulate pixels (back in the day I would use Turbo Pascal, switch to VGA graphics and write to the GPU memory).

In the end I achieved the task with graphics.py. However, it seems to be painfully slow to set pixels in graphics.py. Rendering one (800x600) Mandelbrot set took almost an hour. I commented the line that would actually set the pixels. This time generation of the Mandelbrot set was a matter of minutes (around 2 IIRC).

Is graphics.py that slow or am I doing something wrong?

Cheers

Bebef
  • 141
  • 2
  • 6
  • 1
    We need more info me thinks. Are you setting pixels one by one? Generally in computer graphics you would build a buffer array of pixels and then send that to render. You could be inefficiently calling screen updates by setting pixels one by one. Maybe build a buffer array of pixels and update? – visc Mar 15 '18 at 14:36
  • 1
    Yes, I was setting the pixels one by one. That apparently lead to a (full) window update each time. I now have set the window generation to `autoflush=False` and update only at the end which makes things waaaaaaaaay faster. Unfortunately however you now can't actually see what's going on... ;) – Bebef Mar 16 '18 at 15:38
  • You should look into frame rates and timers. For example, when you get enough data in a certain time you could then push to the display. – visc Mar 16 '18 at 16:48
  • Consider this: `while(weAreRunning) { // execute logic once and when the time is up (1-2 seconds for example) render screen also }` – visc Mar 16 '18 at 16:49
  • With autoflush enabled, you can still flush each row (or column) so you get a nice compromise between speed and visual feedback. See this [example of doing just that](https://stackoverflow.com/a/43969992/5771269) – cdlane May 15 '18 at 05:44

0 Answers0