Noise (Seg Line) - AlbertGBarber/PixelSpork GitHub Wiki

See the Documentation Guide for help understanding each page section.

Effect Sample (see here for sample info)
Effect Sample Gif

Description:

An effect that maps 2D Perlin noise to a segment set by drawing the noise onto the segment lines (made simpler because a segment set acts like a matrix with dimensions numLines x numSegs). Much of this code is based on the FastLED noise example here. Overall, this effect is a sort of 2D noise playground, producing spots of color that shift and morph across the segment set. You have a number of options for tuning the noise an how it changes through time. The output colors can either be taken from a palette, or set to one of two rainbow modes. You can read more about FastLED noise here.

The effect also works well on a 1D strip with a single segment set.

The noise colors will be blended towards a background color (except for in rainbow modes). Changing the background color will "tint" the overall output, because all the colors are blended towards the background color as part of the effect. Supports color modes for the background color.

Please note that this effect stores an array of uint8_t's of size (length of longest segment) * (number of segments in set) So make sure you have enough memory to run it! The array is allocated dynamically, so be careful if you want to change the segment set. see Memory Management for more details.

Inputs guide:

Since this effect is more of a playground, I encourage you to experiment with different input values. Note that I don't fully understand how everything in this effect works (mainly the noise smoothing), but based on testing I've written an input guide below:

When you create the effect you'll have five values to set: blendSteps, scaleBase, scaleRange, speed, and rate:

Blending:

blendStepssets how long the gradient is between each color in the palette. Doesn't need to be super large, anything between 20 and 60 will look good.

Scale:

scaleBase and scaleRange control how large color areas are; how "zoomed-in" the noise is. Smaller values => more zoomed in and larger patches of color.

To add more variation to the effect, the scale can vary with time. This is controlled by the scaleRange value. scaleBase is the minimum scale value, while scaleBase + scaleRange is the maximum. A target scale value will be set by adding scaleBase to randomly picked value up to scaleRange: scaleBase + random(scaleRange). With a target set, the scale will move towards the target value by one step each update cycle. This avoids color "jumps" by keeping the transition gradual. Once the target is reached, a new target value is picked and the process begins again.

If you don't want any shifting, simply set scaleRange = 0. Your values for scaleBase and scaleRange will vary based on the size of your segment Set, but I recommend starting with a scaleBase of 10 - 20, and a scaleRange of 80.

Effect speed:

Both speed and update rate effect how fast the effect moves. speed effects how quickly the noise changes, while the update rate is how often the effect updates. Higher speed => faster, while lower rate => faster. You probably want to start with rate between 50-80 (100+ may look choppy). And a speed value of 10 - 50.

cModes:

There are three color modes in the effect (note that these are not the same as the general color modes).

These are set by cMode (uint8_t):

  • 0 -- Use the input palette for colors.

  • 1 -- Uses the palette for colors, but maps into roughly one color at a time. So you'll get one-ish color across the whole strip, with the color blending towards the next color in palette. To shift the colors make sure the hueCycle is on! It may be helpful to set the blendSteps larger than normal to slow down the blending, setting it so that the <<palette length>> * blendSteps ~= 250+ works well.

  • 2 -- Noise is mapped directly to the rainbow. So any color can show up anywhere, but they will follow the rainbow gradient (red goes to orange to yellow, etc ). Ignores the background color.

  • 3 -- Noise is mapped to a limited section of the rainbow (like mode 1). So you'll get one-ish color across the whole strip, with the color blending towards the next color in the rainbow, ie red to orange, etc. To shift the colors make sure the hueCycle is on! Both rainbow modes were adapted from here. Ignores the background color.

Shifting Hues:

We use hueCycle (bool) and hue (uint16_t) to shift the effect's colors over time.

The noise that FastLED produces tends to be grouped in the middle of the noise range. While the effect does try to stretch this out, it still doesn't usually hit colors at either end of the palette. So, for example using cMode 2 (rainbow mode 1), you'll get more yellow, green, and blue, than red and purple because they're in the middle of the rainbow. To mitigate this we can slowly offset the color center over time, so our rainbow will slowly morph to being more red, yellow, green to more purple, red, yellow, etc.

hueCycle controls if the offsetting is on or off, while hue is the offset value. hueCycle is on (true) by default, since it looks good with all modes. When cycling, the hue is incremented by 1 every update cycle. The hue values range from 0 - 255 for cMode's 0, 2, 3, and 0 - <<palette length>> * blendSteps for cMode 1.

Example Calls:

NoiseSL noiseSL(mainSegments, 4, 20, 30, 60, 10, 1, 80);
/*  Will produce a noise effect with a palette of 4 randomly chosen colors
    There are 20 blend steps between each color
    A base scaling value of 30 will be applied with a range of 60 (so max scale is 90)
    The speed is 10
    cMode is 1
    The effect updates at 80ms */
    
NoiseSL noiseSL(mainSegments, cybPnkPal_PS, 40, 5, 95, 20, 0, 80);
/*  Will produce a noise effect with using colors from cybPnkPal_PS
    There are 40 blend steps between each color
    A base scaling value of 5 will be applied with a range of 95 (max scale is 100)
    The speed is 20
    cMode is 0
    The effect updates at 80ms */

Constructor Definitions:

//Constructor for randomly generated palette
NoiseSL(SegmentSetPS &SegSet, uint8_t numColors, uint16_t BlendSteps, uint16_t ScaleBase, uint16_t ScaleRange,
        uint16_t Speed, uint8_t CMode, uint16_t Rate);

//Constructor using palette
NoiseSL(SegmentSetPS &SegSet, palettePS &Palette, uint16_t BlendSteps, uint16_t ScaleBase, uint16_t ScaleRange, 
        uint16_t Speed, uint8_t CMode, uint16_t Rate);

Constructor Inputs:

  • 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.

  • 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 blendSteps -- Sets how many steps are used to blend between each color (See inputs guide above).

  • uint16_t scaleBase -- Sets how "zoomed-in" the noise is (see inputs guide above).

  • uint16_t scaleRange -- The range for the variation of the scale (see inputs guide above).

  • uint16_t speed -- How fast the colors blend (higher is faster) (See inputs guide above).

  • uint8_t cMode -- The color mode of the effect (see inputs guide above).

  • 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 vars rate entry for more.

Other Settings:

  • CRGB* bgColor (default 0, blank) -- The color used for background pixels. Is a pointer, allowing you to bind it to an external color. By default it's bound the effect's local, bgColorOrig color. See common vars bgColor entry for more details.

  • uint8_t bgColorMode (default 0) -- The colorMode used for the background pixels, also see common vars colorMode entry for more details.

  • bool hueCycle (default true) -- Sets if the noise center will be offset over time (see inputs guide above).

  • uint16_t hueCycle (default 0) -- The position of the noise center, is automatically adjusted if hueCycle is on. But you can also set if yourself to a specific value if needed (see inputs guide above). Range is 0 - 255 for cMode's 0, 2, 3, and 0 - <<palette length>> * blendSteps for cMode 1.

  • bool showNow (default true) -- Controls if the effect "draws" during each update cycle by calling FastLED.show(). Common to all effects. See common vars showNow entry for more details.

Class Functions:

  • void setupNoiseArray(); 

    Creates the array for storing the noise data (will be matrix of uint8_t's, numLines x numSegs). Only call this if you change the segment set dimensions.

  • void update();

    Updates the effect.

⚠️ **GitHub.com Fallback** ⚠️