89#define TWINKLE_SPEED 4
94#define TWINKLE_DENSITY 5
97#define SECONDS_PER_PALETTE 30
103#define AUTO_SELECT_BACKGROUND_COLOR 0
108#define COOL_LIKE_INCANDESCENT 1
110FASTLED_SMART_PTR(TwinkleFox);
119 twinkleSpeed(TWINKLE_SPEED), twinkleDensity(TWINKLE_DENSITY),
120 coolLikeIncandescent(COOL_LIKE_INCANDESCENT),
121 autoSelectBackgroundColor(AUTO_SELECT_BACKGROUND_COLOR) {
122 chooseNextColorPalette(targetPalette);
129 drawTwinkleFox(context.leds);
133 fl::Str fxName()
const override {
return "TwinkleFox"; }
136 CRGB backgroundColor;
137 uint8_t twinkleSpeed;
138 uint8_t twinkleDensity;
139 bool coolLikeIncandescent;
140 bool autoSelectBackgroundColor;
142 void drawTwinkleFox(
CRGB *leds) {
147 uint16_t PRNG16 = 11337;
148 uint32_t clock32 = millis();
150 CRGB bg = backgroundColor;
151 if (autoSelectBackgroundColor &&
152 currentPalette[0] == currentPalette[1]) {
153 bg = currentPalette[0];
157 }
else if (bglight > 16) {
166 for (uint16_t i = 0; i < mNumLeds; i++) {
167 PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384;
168 uint16_t myclockoffset16 = PRNG16;
169 PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384;
170 uint8_t myspeedmultiplierQ5_3 =
171 ((((PRNG16 & 0xFF) >> 4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
173 (uint32_t)((clock32 * myspeedmultiplierQ5_3) >> 3) +
175 uint8_t myunique8 = PRNG16 >> 8;
177 CRGB c = computeOneTwinkle(myclock30, myunique8);
180 int16_t deltabright = cbright - backgroundBrightness;
181 if (deltabright >= 32 || (!bg)) {
183 }
else if (deltabright > 0) {
184 leds[i] =
blend(bg, c, deltabright * 8);
191 CRGB computeOneTwinkle(uint32_t ms, uint8_t salt) {
192 uint16_t ticks = ms >> (8 - twinkleSpeed);
193 uint8_t fastcycle8 = ticks;
194 uint16_t slowcycle16 = (ticks >> 8) + salt;
195 slowcycle16 +=
sin8(slowcycle16);
196 slowcycle16 = (slowcycle16 * 2053) + 1384;
197 uint8_t slowcycle8 = (slowcycle16 & 0xFF) + (slowcycle16 >> 8);
200 if (((slowcycle8 & 0x0E) / 2) < twinkleDensity) {
201 bright = attackDecayWave8(fastcycle8);
204 uint8_t hue = slowcycle8 - salt;
208 if (coolLikeIncandescent) {
209 coolLikeIncandescentFunction(c, fastcycle8);
217 uint8_t attackDecayWave8(uint8_t i) {
222 return 255 - (i + (i / 2));
226 void coolLikeIncandescentFunction(
CRGB &c, uint8_t phase) {
230 uint8_t cooling = (phase - 128) >> 4;
246 0x00580c, 0x00580c, 0x00580c, 0x00580c, 0x00580c, 0x00580c,
247 0x00580c, 0x00580c, 0x00580c, 0x00580c, 0x00580c, 0x00580c,
248 0x00580c, 0x00580c, 0x00580c, 0xB00402};
279 0x304048, 0x304048, 0x304048, 0x304048, 0x304048, 0x304048,
280 0x304048, 0x304048, 0x304048, 0x304048, 0x304048, 0x304048,
281 0x304048, 0x304048, 0x304048, 0xE0F0FF};
284 0xB80400, 0x902C02, 0xB80400, 0x902C02, 0x902C02, 0xB80400,
285 0x902C02, 0xB80400, 0x046002, 0x046002, 0x046002, 0x046002,
286 0x070758, 0x070758, 0x070758, 0x606820};
289 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040,
290 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040, 0x0C1040,
291 0x182080, 0x182080, 0x182080, 0x5080C0};
301 const uint8_t numberOfPalettes =
302 sizeof(ActivePaletteList) /
sizeof(ActivePaletteList[0]);
303 static uint8_t whichPalette = -1;
304 whichPalette =
addmod8(whichPalette, 1, numberOfPalettes);
305 pal = *(ActivePaletteList[whichPalette]);
central include file for FastLED, defines the CFastLED class/object
RGB color palette with 16 discrete values.
void draw(DrawContext context) override
uint32_t TProgmemRGBPalette16[16]
CRGBPalette16 entries stored in PROGMEM memory.
#define FL_PROGMEM
PROGMEM keyword for storage.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
LIB8STATIC uint8_t addmod8(uint8_t a, uint8_t b, uint8_t m)
Add two numbers, and calculate the modulo of the sum and a third number, M.
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
void nblendPaletteTowardPalette(CRGBPalette16 ¤t, CRGBPalette16 &target, uint8_t maxChanges)
Alter one palette by making it slightly more like a "target palette".
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
@ NOBLEND
No interpolation between palette entries.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
#define sin8
Platform-independent alias of the fast sin implementation.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Representation of an RGB pixel (Red, Green, Blue)
FASTLED_FORCE_INLINE CRGB & nscale8_video(uint8_t scaledown)
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
uint8_t g
Green channel value.
FASTLED_FORCE_INLINE uint8_t getAverageLight() const
Get the average of the R, G, and B values.
uint8_t b
Blue channel value.