Category: Game Code  ·  Originally posted February 4, 2009  ·  Last updated February 1, 2011

How to Use Math to Create Fire

A demonstration of mathematically-generated fireThis fire image was mathematically generated using the code available below.

(NOTE: as of February 26th, 2009, version 2.0 of this code is available here.)

Whether working on an old-school RPG or a state-of-the-art FPS, every game programmer needs to be able to generate a fast, cool fire effect at some point in his/her career.  In this example, I’ve opted for a straightforward and easy-to-understand method for generating real-time flames.  No pre-built images or palettes are used, making the code quite small and easy to reuse.  Coloring and flame generation is done using only math and a little cleverness.  :)

To simplify the code, I’ve used SetPixelV for drawing the fire.  This slows the demo down significantly, but DIB sections could easily be dropped into place if speed is a major factor for you.

This site - and its many free downloads - are funded by donations from visitors like you.
Please consider a small donation to fund server costs and to help me support my family.
Even $1.00 helps. Thank you!

 

bookmark and share this article

Email this article to a friend Print a copy of this article Subscribe to article comments Bookmark this article on Delicious Submit this article to reddit Submit this article to Digg Submit this article to StumbleUpon Share this article on Facebook Tweet this article

related articles

Discussion (Be the first to comment!)

Public comments are closed for this article. Private comments may be submitted using this link.

Comments are closed.