Twinkle Fast (Seg Line) - AlbertGBarber/PixelSpork GitHub Wiki

See the Documentation Guide for help understanding each page section.

Description:

Fades sets of randomly chosen pixels in and out (like FastLED TwinkleFox). The effect is mostly the same as Twinkle (Seg Line), but uses much less ram, while having a few extra restrictions.

To make the effect "fast", it doesn't track where the twinkles are, instead, the background is filled, or the entire segment set is faded at the start of each update cycle. This wipes out of fades any existing twinkles, and then the a new twinkle is drawn. To make fading fast, we use FastLED's fadeToBlackBy() functions. Note, however, that this means that you cannot have a colored background and fading twinkles. The two are mutually exclusive.

When fading, the twinkles are faded by a value out of 255 each cycle (fadeOutRate), eventually hitting 0 (black) due to integer math.

Other than the above restriction, the effect is the same as Twinkle (Seg Line):

  • The color of the pixels can be set to a single color, chosen randomly, or picked from a palette.
  • The effect supports color modes for both the main and background colors.
  • The effect is adapted to work on segment lines for 2D use. Each line will be a solid color.
  • The effect supports randMode's for picking colors (see below).

randMode (default 0) (uint8_t):

Sets how the twinkle colors will be picked.

  • 0 -- Picks colors randomly from the palette.
  • 1 -- Picks colors totally at random.

Example Calls:

TwinkleFastSL twinkleFast(mainSegments, CRGB::Red, 0, 5, true, 50, 70);
/*  Will spawn 5 pixels to fade from red each cycle.
    The background is black.
    "sparkle" is true, so the pixels will be faded to black (ignoring any background color)
    The fade rate is 50 (out of 255)
    The effect updates at 70ms. */

TwinkleFastSL twinkleFast(mainSegments, cybPnkPal_PS, CRGB::Green, 8, false, 50, 100);
/*  Will choose 8 pixels each cycle to set to colors from the cybPnkPal_PS palette.
    The background is green.
    "sparkle" is false, so the pixels will not be faded (the fade rate of 50 is ignored).
    The effect updates at 100ms. */

Constructor Definitions:

//Constructor for a full palette effect
TwinkleFastSL(SegmentSetPS &SegSet, palettePS &Palette, CRGB BgColor, uint16_t NumTwinkles, bool Sparkle, 
              uint8_t FadeOutRate, uint16_t Rate);

//Constructor for a using a single color
TwinkleFastSL(SegmentSetPS &SegSet, CRGB Color, CRGB BgColor, uint16_t NumTwinkles, bool Sparkle, 
              uint8_t FadeOutRate, 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.

  • CRGB color (optional, see constructors) -- A single color for the effect. The color will be placed into the effect's local palette, paletteTemp for use.

  • CRGB* bgColor -- 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. Is ignored if sparkle is true.

  • uint16_t numTwinkles -- The number of random pixels chosen each cycle.

  • bool sparkle -- If true, the pixels will fade out over time, while forcing the background to be black.

  • uint8_t fadeOutRate (min 1) -- The value (out of 255) that the pixels will fade by each cycle. Only used if sparkle is true. Higher -> faster fading.

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

  • uint8_t colorMode (default 0) -- The colorMode use for the effect, also see common vars colorMode 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. Is ignored if sparkle is true.

  • bool fillBg (default true) -- If true, and sparkle is false, the background will be redrawn every cycle. Turning this off prevents "old" twinkles from being wiped out, producing a unique effect. Try it with a shifting Color Mode.

  • uin8t_t randMode (default 0) -- (See randMode notes in intro).

  • 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 setSingleColor( CRGB Color ); 
    

    Sets the effect to use a single color for the twinkles. The color will be stored in the effect's local palette, "paletteTemp".

  • void reset();
    

    Resets the effect by filling in the background.

  • void update();
    

    Updates the effect.