This is my research about implementation fire effect. I wanted to find the simplest and fastest realization that effect with python and pygame. Unfortunate, operations with separate pixels in the pygame too slow. You can verify this yourself by running the regular version of program:
python fireg.py
And as you can see, it work very very slowly:
For comparison, you can see below how quickly a similar algorithm does work, implemented on pure assembler in the DOS system. You can find corresponded binaries in the 'bin' folder of project. And you can properly execute them in the DOSBox environment. These programs work very fast even on ancient computers and have screen frame synchronization procedure like “Synk” (see pascal version) for speed reduction.
Or the pascal version (with some inline assembler tricks):
The first way to improve Python responsibility to work with array of pixels little above than small size – is to use NumPy library. But this doesn't optimal decision because we have been translating arrays from PyGame to Numpy and vice versa. The secondary way is to use OpenCV Python framework with NumPY. And the third way is to use OpenGL library for Python.
This way looks very good and fastest. Like in this GIF:
In addition I added ability to write all output to video file. Just press a 'V' key to start recording.
- Python
- PyGame
- NumPY
- OpenCV
- img - screenshots, images, etc.
- src - additional source files.
- bin - compiled binaries.
- fireg.py - regular version of fire effect for python & pygame
- firecv2.py - version with OpenCV framework
- FIRE.ASM - assembler source version
- FIRE.EXE - binary (assembler) for DOS (16 bit)
- FIRE.COM - 256b INTRO version for DOS
- FIRE.ASS - 256b INTRO version source code
- FIREPAS.PAS - Pascal version source.
- FIREPAS.EXE - Binary of pascal version for DOS (Borland Pascal 7.0, 16 bit)
An0ther0ne