FastLED 3.10.8
Loading...
Searching...
No Matches

◆ drawTwinkleFox()

void fl::TwinkleFox::drawTwinkleFox ( fl::span< 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 u16 PRNG16 = 11337;
146 fl::u32 clock32 = fl::millis();
147
151 bg = currentPalette[0];
152 u8 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 u8 backgroundBrightness = bg.getAverageLight();
163
164 for (u16 i = 0; i < mNumLeds; i++) {
165 PRNG16 = (u16)(PRNG16 * 2053) + 1384;
166 u16 myclockoffset16 = PRNG16;
167 PRNG16 = (u16)(PRNG16 * 2053) + 1384;
168 u8 myspeedmultiplierQ5_3 =
169 ((((PRNG16 & 0xFF) >> 4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
170 fl::u32 myclock30 =
171 (fl::u32)((clock32 * myspeedmultiplierQ5_3) >> 3) +
172 myclockoffset16;
173 u8 myunique8 = PRNG16 >> 8;
174
175 CRGB c = computeOneTwinkle(myclock30, myunique8);
176
177 u8 cbright = c.getAverageLight();
178 i16 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[1]
u16 mNumLeds
Definition fx.h:53
bool autoSelectBackgroundColor
Definition twinklefox.h:138
CRGB computeOneTwinkle(fl::u32 ms, u8 salt) FL_NO_EXCEPT
Definition twinklefox.h:189
CRGBPalette16 currentPalette
Definition twinklefox.h:113
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2) FL_NO_EXCEPT
FASTLED_FORCE_INLINE CRGB & nscale8_video(u8 scaledown) FL_NO_EXCEPT
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
Definition crgb.hpp:72
FASTLED_FORCE_INLINE u8 getAverageLight() const FL_NO_EXCEPT
Get the average of the R, G, and B values.
Definition crgb.hpp:152

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

Referenced by draw().

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