This is a project to improve on those little LED candles that flicker like real ones.
The way the algorithm works is pretty simple. Real wind and real candles are not random. They might look random, but there is in fact some degree of order.
For one thing, in perfectly still air, many candles will not flicker at all. They will be constantly "maxed out". We model this by having the brightness value constantly increase up to the maximum.
Next, we add flickering by randomly toppling the flame over. Every frame, there is some probability that the brightness will be set to some random value.
But in real candles, the flame goes through periods of calmness, then flickers a bunch, then straightens out till the next gust 'o wind. So to simulate this, we derive the probability of toppling the flame from the current simulated wind speed.
The algorithm for simulating wind speed is similar to the flame algorithm. The wind has a baseline, and the speed constantly decreases until it reaches the baseline. Every frame there is a random chance of setting the wind speed to a random value. This simulates random gusts of wind that settle back down to the baseline wind speed
And that's all there is to it! It's a rather trivial algorithm, but it gives quite a convicing effect when used with the right color LED.
All code can be found at:https://github.com/EternityForest/CandleFlickerSimulator