To give you an ad-free browsing experience, this website is completely funded by donations. If you use the information in this article to solve a problem, entertain yourself, or otherwise improve your life, please consider a small donation to help pay for server costs. (Even $1 helps!) Many thanks, and enjoy the site!

// Game Code

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.  :)

As usual, the sample code was written for VB6, but an .exe is included for those just wanting screenshots (or if you just want to see the effect in action).  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.

 

bookmark and share this article

if you liked this article, you may also like

Discussion (Oldest Comments Displayed First)

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

Comments are closed.