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

◆ drawTwinkleFox()

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

Definition at line 142 of file twinklefox.h.

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

References autoSelectBackgroundColor, backgroundColor, 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: