Skip to content

Simple simulation of candle flicker, with single value representing flame intensity changing each update

License

Notifications You must be signed in to change notification settings

BlackDice/Candle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Candle

This library is a simplified javascript rewrite of this method witen in C: https://github.com/EternityForest/CandleFlickerSimulator

Use this library if you want to get a single value of flame intensity being changed by random gusts of wind. The resulting intensity is in 0-1 range, all input values have to be in 0-255 range.

Only dependancy is lodash.defaults

Options

Optionally you can pass an options object to set these variables:

  • flameBaseline: Starting value of the flame intensity
  • windBaseline: Starting value of the wind intensity
  • flameRiseSpeed: How quickly the flame should rise without wind
  • windFalloffSpeed: How quickly the gust of wind should calm down
  • windChance: What is the likelihood of getting a wind gust each update
  • flameAgility: How much will the flame get toppled by the wind
  • windCalmness: Optional wind reduction

Usage

Create an instance of the candle object and call updates on it with each requestAnimationFrame tick. The loop is not included, if you don't have one, you can use this:

candle = new Candle();
loop = function (){
	candle.update();
	intensity = candle.getIntensity();
	requestAnimationFrame(loop);
}
loop();

About

Simple simulation of candle flicker, with single value representing flame intensity changing each update

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published