What's a cool algorithm to simulate hot flickering flames? - Embedded.com

# What’s a cool algorithm to simulate hot flickering flames?

Well, things have been bouncing along with regard to my Caveman Diorama since last we spoke (see Caveman Cam). My chum Mike — the model railway enthusiast — and I meet up in my office on Saturdays to work on the cave and other hobby projects.

Take the waterfall and the pool, for example. The image below shows a very early incarnation of this (the two cutout figures are just there to provide a sense of the 1:32 scale we're using).

Actually, now I come to think about it, I really need to write another column to bring you up to date with everything. We recently finished the underlying structure for the cave roof; you will not believe your eyes when you see it.

Since much of this is new to both Mike and me, we're spending a lot of time experimenting with different effects. Take the pool, for example; we've created a series of mockups with various colorings and depths, and we've filled them with clear epoxy to simulate the water. I don’t want to boast, but I think the final version is going to look pretty spectacular.

This past weekend, we added a hidden tri-colored LED under one of the pools to decide if it brought anything to the table. In fact, just having the water dimly glow blue or green turns out to be surprisingly effective. Also, when we add other effects like lightning outside the cave entrance during a storm, we could flicker this LED in time with the lightning to make it look as though the lightning was reflecting off the pool.

In the fullness of time, some cavemen miniatures are going to be sitting around a fire, along with a figure in a Hawaiian shirt representing myself (an H.G. Wells-esque time machine will be seen in one corner of the cave). I'll be lighting this fire with a number of tri-colored LEDs of course.

While I was ruminating on this on the way into work, I started to think about the tunnel feeding the waterfall. We're going to have a couple of Morlock characters with glowing orange eyes hiding on the ledge spying on the scene below. So I started to wonder about having some tri-colored LEDs mounted at the back of the tunnel. I'm thinking of a low red flicker with occasional flares of orange and yellow.

All of which leads me to the point of this column. What sort of algorithm would be best to simulate flickering flames? Should I just mix combinations of random numbers with different amplitudes and periods, or should I overlay my random values on top of a more regular underlying “envelope”? Is there a preferred technique for this sort of thing? If you know anything about this, or just have some ideas of your own, please share them with the rest of us in the comments below.

## 3 thoughts on “What’s a cool algorithm to simulate hot flickering flames?”

1. HeyJoe says:

“This is just a hunch, but I wonder if 1/F noise would produce pleasing results. Perhaps modulate the 1/f corner frequency with a VLF wave. This would be no problem for Matlab and the like however, designing an algorithm for small embedded solution sound

2. Clive"Max"Maxfield says:

“I'm not sure — someone just posted a comment on LinkedIn saying his boss used two streams of pink noise to drive red and yellow channels and “it looked quite good” … I really need to create a little test model of a fire and play around a bit.”