FastLED 3.9.15
Loading...
Searching...
No Matches

◆ drawTwinkleFox()

void fl::TwinkleFox::drawTwinkleFox ( CRGB * leds)
inlineprivate

Definition at line 140 of file twinklefox.h.

140 {
141 // "PRNG16" is the pseudorandom number generator
142 // It MUST be reset to the same starting value each time
143 // this function is called, so that the sequence of 'random'
144 // numbers that it generates is (paradoxically) stable.
145 uint16_t PRNG16 = 11337;
146 uint32_t clock32 = millis();
147
148 CRGB bg = backgroundColor;
151 bg = currentPalette[0];
152 uint8_t bglight = bg.getAverageLight();
153 if (bglight > 64) {
154 bg.nscale8_video(16);
155 } else if (bglight > 16) {
156 bg.nscale8_video(64);
157 } else {
158 bg.nscale8_video(86);
159 }
160 }
161
162 uint8_t backgroundBrightness = bg.getAverageLight();
163
164 for (uint16_t i = 0; i < mNumLeds; i++) {
165 PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384;
166 uint16_t myclockoffset16 = PRNG16;
167 PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384;
168 uint8_t myspeedmultiplierQ5_3 =
169 ((((PRNG16 & 0xFF) >> 4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
170 uint32_t myclock30 =
171 (uint32_t)((clock32 * myspeedmultiplierQ5_3) >> 3) +
172 myclockoffset16;
173 uint8_t myunique8 = PRNG16 >> 8;
174
175 CRGB c = computeOneTwinkle(myclock30, myunique8);
176
177 uint8_t cbright = c.getAverageLight();
178 int16_t deltabright = cbright - backgroundBrightness;
179 if (deltabright >= 32 || (!bg)) {
180 leds[i] = c;
181 } else if (deltabright > 0) {
182 leds[i] = blend(bg, c, deltabright * 8);
183 } else {
184 leds[i] = bg;
185 }
186 }
187 }
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
uint16_t mNumLeds
Definition fx.h:53
bool autoSelectBackgroundColor
Definition twinklefox.h:138
CRGB computeOneTwinkle(uint32_t ms, uint8_t salt)
Definition twinklefox.h:189
CRGBPalette16 currentPalette
Definition twinklefox.h:113
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
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.
Definition crgb.hpp:69
FASTLED_FORCE_INLINE uint8_t getAverageLight() const
Get the average of the R, G, and B values.
Definition crgb.hpp:149

References autoSelectBackgroundColor, backgroundColor, fl::blend(), computeOneTwinkle(), currentPalette, CRGB::getAverageLight(), leds, fl::Fx::mNumLeds, and CRGB::nscale8_video().

Referenced by draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: