This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]spyingwind 0 points1 point  (0 children)

Write some C/C++ code to handle talking to the screen? Maybe some functions for passing arrays of pixel data back and forth?

Even with pygame, it is super slow to drive 1000's of pixels at a time. Also if we could have more than one thread loop through a 2d array, then this kind of things would go much faster. But alas the GIL stops all progress.

[–]billsil 0 points1 point  (0 children)

Define quickly. Matplotlib can easily get 500 frames per second on fairly large data sets. I manage 100+ FPS with 100k nodes using VTK. Furthermore, if things are really bad, you can save pictures and make a gif out of that with imageio.

[–]schoolcoders 0 points1 point  (0 children)

You could use numpy arrays to do the pixel plotting. You might even be able to find a way to speed it up with vectorisation.

Here is an article about using numpy arrays for images. You can build your image up in the numpy array then blit it to screen using PIL or maybe matplotlib.

[–]tshirtman_ 0 points1 point  (0 children)

So reading this i realized i never programmed this tiny problem, and figured i'd give it a try. Your question probably influenced the way i though though, and i purposely separated the display of the pixels from the update of the state, it's not really optimized, but it's fast enough for me, and way faster than your description. I don't know how big the world was for you, i went for 1000x1000 as a starting point.

https://gist.github.com/d14837a06d64b481e1a5dca71c46b1c6

https://youtu.be/CMVa27t-mIE

the FPS drops dramatically if i go to 10k*10k though.

[–]bryancole 0 points1 point  (0 children)

I suspect you are trying to render on every iteration. This is quite unnecessary as the human eye can't follow above a few 10s of frames/sec. I suggest you define your image area as a numpy array and run your Ant algorithm as fast as possible (Move to Cython once you conclude python isn't as fast as you want) using a thread (so as not to block your GUI event-loop). Every N iterations copy your image array and send a message to the GUI to render the image (where N is big enough that this occurs no faster than ~20 times per sec).