Lava - AlbertGBarber/PixelSpork GitHub Wiki
See the Documentation Guide for help understanding each page section.
Effect Sample (see here for sample info) |
An effect based on the "Lava" code created by Scott Marley here: https://github.com/s-marley/FastLED-basics/tree/main/6.%20Noise/lava. A fairly simple, but great looking effect that uses FastLED noise functions to produce a lava-esque effect. You can also supply your own palette for the effect to add your own colors, choose to have a palette of random color be created, or use the rainbow for the colors. See more about FastLED noise here.
You can customize how the effect looks by adjusting the blendSteps
and blendScale
values. These change how fast the lava blends and how "zoomed-in" the lava color areas are. I encourage playing with these, since they can change the effect a lot.
The effect is 1D, so it always treats the strip as a single line. In my testing, the effect already tended to look 2D-like, so I saw no reason to expand it to be truly 2D.
Note that for the basic constructor, the effect uses the built-in palette, lavaPal_PS.
Also note that this effect tends to look better at a higher refresh rate (lower rate), which may be hard to hit depending on your setup.
For a similar effect with some different options, see NoiseSL.
The effect has a rainbow mode, where the rainbow is used for the noise colors. This is turned on/off using rainbowMode
.
Because the noise function values tend to fall in the center of the noise range, you tend not to see the start/end colors of a palette/rainbow. To fix this, you can set hueCycle
to true, which cycles a hue offset over time, adjusting the center of the noise so you see all the colors. By default the offset fully cycles once a minute (in rainbow mode), but you can change the rate using hueRate
. Note that, like rate
, hueRate
is a pointer. By default it's bound to hueRateOrig
, but you can bind it to an external var if needed. See common vars rate
entry for more.
You can also set the offset directly by setting the hue
value. If hueCycle
is false, the hue
will not change over time. Note that for the rainbow mode, the range is hue
0-255, while for a palette the range is 0 to <palette length> * blendSteps
.
LavaPS lava(mainSegments, 30);
/* Will do a lava effect, using the default lavaPal_PS palette,
with default blendSteps (30) and blendScale (80) values
updating at 30ms */
LavaPS lava(mainSegments, 10, 30, 60);
/* Will do a lava effect, with 10 blendSteps
and a blendScale of 30
at an update rate of 60ms */
LavaPS lava(mainSegments, cybPnkPal_PS, 10, 80, 60);
/* Will do a lava effect using the cybPnkPal_PS palette for colors,
with 10 blendSteps and a blendScale of 80
at an update rate of 60ms */
LavaPS lava(mainSegments, 3, 20, 80, 30);
/* Will do a lava effect with a palette of 3 randomly chosen colors
with 20 blendSteps and a blendScale of 80
at an update rate of 30ms */
//Constructor for effect using default lava palette, blendSteps and blendScale
LavaPS(SegmentSetPS &SegSet, uint16_t Rate);
//Constructor for effect with default lava palette, but custom scale and steps
LavaPS(SegmentSetPS &SegSet, uint16_t BlendSteps, uint16_t BlendScale, uint16_t Rate);
//Constructor for effect using colors from palette
LavaPS(SegmentSetPS &SegSet, palettePS &Palette, uint16_t BlendSteps, uint16_t BlendScale, uint16_t Rate);
//constructor for a randomly created palette
LavaPS(SegmentSetPS &SegSet, uint8_t numColors, uint16_t BlendSteps, uint16_t BlendScale, uint16_t Rate);
-
SegmentSetPS* segSet -- The Segment Set the effect will draw on. See common vars
segSet
entry for more details. -
palettePS* palette (optional, see constructors) -- The set of colors the effect will use. See palettes. It is a pointer. See common vars
palette
entry for more details. -
uint16_t blendSteps (optional, default 30) -- Sets how many steps are used to blend between each color. Basically changes how fast the colors blend. Between 20 - 100 looks good. The default is taken from the original code by Scott Marley.
-
uint16_t blendScale (optional, default 80) -- Sets how large the blended color areas are (test it out yourself to see what I mean). Between 10 - 100 looks good: larger => smaller areas. The default is taken from the original code by Scott Marley..
-
uint8_t numColors (optional, see constructors) -- The number of randomly chosen colors for the effect. The colors will be placed into the effect's local palette,
paletteTemp
for use. -
uint16_t* rate -- Update rate (ms). Is a pointer, allowing you to bind it to an external variable. By default it's bound the effect's local variable,
rateOrig
. See common varsrate
entry for more.
-
bool hueCycle (default false) -- If true, the center of the noise will shift over time (see hueCycle notes in intro)
-
uint16_t* hueRate (default bound to
hueRateOrig
) -- The hue shifting time (ms). It's a pointer so you can bind it externally. By default it's bound the effect's local variable,hueRateOrig
(like howrate
is bound torateOrig
). See common varsrate
entry for more. -
uint16_t hueRateOrig (default 235) -- Default hue shifting time (ms), does a complete hue cycle ~every min for rainbow (255 steps).
-
bool rainbowMode (default false) -- If true, rainbow colors will be used for the lava colors (see rainbow mode notes in intro).
-
uint8_t sat and val (both default 255) -- HSV saturation and "value" values for rainbow mode. See Common Vars "sat and hue" entry for more.
-
uint8_t brightnessScale (default 150) -- Sets the noise range for the brightness. It doesn't seem to change much in my testing.
-
bool showNow (default true) -- Controls if the effect "draws" during each update cycle by calling
FastLED.show()
. Common to all effects. See common varsshowNow
entry for more details.
-
Updates the effect.
void update();
- uint8_t hue -- The amount to offset the noise center by, see
hueCycle
notes in intro.