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

◆ drawTwinkleFox()

void fl::TwinkleFox::drawTwinkleFox ( fl::span< CRGB > leds)
inlineprivate

Definition at line 138 of file twinklefox.h.

138 {
139 // "PRNG16" is the pseudorandom number generator
140 // It MUST be reset to the same starting value each time
141 // this function is called, so that the sequence of 'random'
142 // numbers that it generates is (paradoxically) stable.
143 u16 PRNG16 = 11337;
144 fl::u32 clock32 = fl::millis();
145
149 bg = currentPalette[0];
150 u8 bglight = bg.getAverageLight();
151 if (bglight > 64) {
152 bg.nscale8_video(16);
153 } else if (bglight > 16) {
154 bg.nscale8_video(64);
155 } else {
156 bg.nscale8_video(86);
157 }
158 }
159
160 u8 backgroundBrightness = bg.getAverageLight();
161
162 for (u16 i = 0; i < mNumLeds; i++) {
163 PRNG16 = (u16)(PRNG16 * 2053) + 1384;
164 u16 myclockoffset16 = PRNG16;
165 PRNG16 = (u16)(PRNG16 * 2053) + 1384;
166 u8 myspeedmultiplierQ5_3 =
167 ((((PRNG16 & 0xFF) >> 4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
168 fl::u32 myclock30 =
169 (fl::u32)((clock32 * myspeedmultiplierQ5_3) >> 3) +
170 myclockoffset16;
171 u8 myunique8 = PRNG16 >> 8;
172
173 CRGB c = computeOneTwinkle(myclock30, myunique8);
174
175 u8 cbright = c.getAverageLight();
176 i16 deltabright = cbright - backgroundBrightness;
177 if (deltabright >= 32 || (!bg)) {
178 leds[i] = c;
179 } else if (deltabright > 0) {
180 leds[i] = blend(bg, c, deltabright * 8);
181 } else {
182 leds[i] = bg;
183 }
184 }
185 }
fl::CRGB leds[NUM_LEDS]
u16 mNumLeds
Definition fx.h:53
bool autoSelectBackgroundColor
Definition twinklefox.h:136
CRGBPalette16 currentPalette
Definition twinklefox.h:111
CRGB computeOneTwinkle(fl::u32 ms, u8 salt)
Definition twinklefox.h:187
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
FASTLED_FORCE_INLINE u8 getAverageLight() const FL_NOEXCEPT
Get the average of the R, G, and B values.
Definition crgb.hpp:152
FASTLED_FORCE_INLINE CRGB & nscale8_video(u8 scaledown) FL_NOEXCEPT
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
Definition crgb.hpp:72

References autoSelectBackgroundColor, backgroundColor, fl::blend(), computeOneTwinkle(), currentPalette, 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: