Skip to main content

Python procedural fire effect

Project description

PythonFireFx

PythonFireFx is a shader for rendering 2D realistic fire effect (procedural fire). Written in python, cython and C language, it is design for real time rendering on pygame surface with screen resolution up to 1280 x 1024 pixels.

Compatible with image format 24-32 bit with any of the following extension: BMP, GIF (non - animated), JPEG, PNG image format.

It was originally designed for 2D video games application build on the top of Pygame library, but it can also be used as a plugin for video or webcam special effect. It requires few libraries in order to work, please see the dependency section for more details.

The algorithm has numerous options to control the fire envelop/aspect. All this options can be defined as static or dynamic in order to produce a more realistic fire effect:

Some of the options :

  • Blur algorithm (to smooth and produce a warm /fluid fire effect)
  • Palette (pre-defined color wavelength's values set in a numpy array)
  • Smoothing effect to add a realistic touch
  • Fire intensity to control the fire energy at the base
  • Bloom effect to create local flickering light effect or add texture volume to the fire (depends on the bright pass filter value)
  • Brightness control (fine control that change the fire volume and intensity)
  • The palette can be disregarded, and a default palette can be used with colors defined by HSL (hue, saturation and luminescence values) that can also be set dynamically to change the colors overtime
  • Border flames (option to burn only the side of the screen/texture). This option is designed to work with symmetrical surface (same with and length)

Tested under windows x64 platform.

  • Please feel free to open a new ticket if you wish to add any suggestion(s) or if you wish to report a bug.

python method hook

shader_fire_effect(
        width_,
        height_,
        factor_,
        palette_,
        fire_
)

Optional arguments

        reduce_factor_        = 3,
        fire_intensity_       = 32,
        smooth_               = True,
        bloom_                = True,
        fast_bloom_           = True,
        bpf_threshold_        = 0,
        low_                  = 0,
        high_                 = 600,
        brightness_           = True,
        brightness_intensity_ = 0.15,
        surface_              = None,
        adjust_palette_       = False,
        hsl_                  = (10, 80, 1.8),
        transpose_            = False,
        border_               = False,
        blur_                 = True

doc

Check the folder Doc/html/index.html

fire effect image

Demo

In the main directory run the below command

(press ESC to quit the demo)

C:\>python demo_fire.py

The project is under the GNU GENERAL PUBLIC LICENSE Version 3

Installation

check the link for newest version https://pypi.org/project/PythonFireFx/

  • Available python build 3.6, 3.7, 3.8, 3.9, 3.10 and source build
pip install PythonFireFx 

Building project from source

python setup.py build
python setup.py install

Building cython code

When do you need to compile the cython code ?

Each time you are modifying any of the following files FireFx.pyx, FireFx.pxd, init.pxd or any external C code if applicable

  1. open a terminal window
  2. Go in the main project directory where (FireFx.pyx & FireFx.pxd files are located)
  3. run : C:\>python setup_FireFx.py build_ext --inplace --force

If you have to compile the code with a specific python version, make sure to reference the right python version in (python38 setup_FireFx.py build_ext --inplace)

If the compilation fail, refers to the requirement section and make sure cython and a C-compiler are correctly install on your system.

  • A compiler such visual studio, MSVC, CGYWIN setup correctly on your system.
    • a C compiler for windows (Visual Studio, MinGW etc) install on your system and linked to your windows environment. Note that some adjustment might be needed once a compiler is install on your system, refer to external documentation or tutorial in order to setup this process.e.g https://devblogs. microsoft.com/python/unable-to-find-vcvarsall-bat/

OPENMP

In the main project directory, locate the file setup_FireFx.py. The compilation flag /openmp is used by default. To override the OPENMP feature and disable the multi-processing remove the flag /openmp

setup_FireFx.py

extra_compile_args = ["/openmp", "/Qpar", "/fp:fast", "/O2", "/Oy", "/Ot"]

Save the change and build the cython code with the following instruction:

python setup_FireFx.py build_ext --inplace --force

If the project build successfully, the compilation will end up with the following lines

Generating code
Finished generating code

If you have any compilation error refer to the section Building cython code, make sure your system has the following program & libraries installed. Check also that the code is not running in a different thread.

  • Pygame version > 3
  • numpy >= 1.18
  • cython >=0.29.21 (C extension for python)
  • A C compiler for windows (Visual Studio, MinGW etc)

Credit

Yoann Berenguer

Dependencies :

numpy >= 1.18
pygame >=2.0.0
cython >=0.29.21

License :

GNU GENERAL PUBLIC LICENSE Version 3

Copyright (c) 2019 Yoann Berenguer

Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PythonFireFx-1.0.0.tar.gz (12.6 MB view details)

Uploaded Source

Built Distributions

PythonFireFx-1.0.0-cp310-cp310-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

PythonFireFx-1.0.0-cp39-cp39-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

PythonFireFx-1.0.0-cp38-cp38-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.8 Windows x86-64

PythonFireFx-1.0.0-cp37-cp37m-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.7m Windows x86-64

PythonFireFx-1.0.0-cp36-cp36m-win_amd64.whl (13.4 MB view details)

Uploaded CPython 3.6m Windows x86-64

File details

Details for the file PythonFireFx-1.0.0.tar.gz.

File metadata

  • Download URL: PythonFireFx-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 52fc56fe9c23de487fa211f521907d2966b5525ce9728b08946bfbc7575318c8
MD5 046eb2f7597ab680cb56053e7a04072b
BLAKE2b-256 73cbd6b9f226f58dd917749344a9b65a0efb1a2bce6e2e746681e713b79608e8

See more details on using hashes here.

File details

Details for the file PythonFireFx-1.0.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: PythonFireFx-1.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 13.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 04d967de432217e3d9db42d36a9eb30f25a10b4893b61e68df276b449948027c
MD5 6df9674cf76059437669315f513d4ceb
BLAKE2b-256 c7d3017be9acfc1f94f87ed1f52298693d2bade10d77d9dccc0aecfe0e567f26

See more details on using hashes here.

File details

Details for the file PythonFireFx-1.0.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: PythonFireFx-1.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 13.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8f9d8bfb7dbe75c35ddcdc2f1b42b78b4ebabef5b1ace7bb2d782ee07a27e44c
MD5 fc0086c164b477e7a39feb4ca793a1b5
BLAKE2b-256 b0429d071ac570a82e011729276dc48bf0764a1af78a394ec25b042a6b26d9b1

See more details on using hashes here.

File details

Details for the file PythonFireFx-1.0.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: PythonFireFx-1.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 13.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2c996b91657aac26ffe343065aade14bd7d3688cf3251f879a2a417f27086e8f
MD5 8149a31148bcd2ac4acea6b00008c438
BLAKE2b-256 5e738ee4801a38941153b38714fd2a7a7eee7591a7673142c62473a8a16db0e0

See more details on using hashes here.

File details

Details for the file PythonFireFx-1.0.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: PythonFireFx-1.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 13.4 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 eb1b5dcef0f01ca2fb4ccf6c8936623764ab3b8c51405de15ded67404010509b
MD5 a5850439a5779ea70e9c122b0e03de74
BLAKE2b-256 989037fe235e29f3d323f7d3922cf85f1b7fcdc32acb87fde05fd6d50d1d81cc

See more details on using hashes here.

File details

Details for the file PythonFireFx-1.0.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: PythonFireFx-1.0.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 13.4 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/60.0.3 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for PythonFireFx-1.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c76c340eac076c42780e0ec327f3453f5815f045a6afd4a3fe0d17bd877eeb98
MD5 c4763925585fcd6a443985e8694fbcfe
BLAKE2b-256 9da9a03062baf1705704cd5744908d02e374e466d97af52e97585fa45df65c68

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page