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

◆ loop()

void loop ( )

Definition at line 135 of file Corkscrew.h.

135 {
137 static float pos = 0;
138 pos += speed.value();
139 if (pos > corkscrew.size() - 1) {
140 pos = 0; // Reset to the beginning
141 }
142
143 // Update caching setting if it changed
144 static bool lastCachingState = cachingEnabled.value();
145 if (lastCachingState != cachingEnabled.value()) {
146 corkscrew.setCachingEnabled(cachingEnabled.value());
147 lastCachingState = cachingEnabled.value();
148 }
149
150 if (allWhite) {
151 for (size_t i = 0; i < frameBuffer.size(); ++i) {
152 frameBuffer.data()[i] = CRGB(8, 8, 8);
153 }
154 }
155
156 if (splatRendering) {
157 Tile2x2_u8_wrap pos_tile = corkscrew.at_wrap(pos);
158 const CRGB color = CRGB::Blue;
159 // Draw each pixel in the 2x2 tile using the new wrapping API
160 for (int dx = 0; dx < 2; ++dx) {
161 for (int dy = 0; dy < 2; ++dy) {
162 auto data = pos_tile.at(dx, dy);
163 vec2<u16> wrapped_pos = data.first; // Already wrapped position
164 uint8_t alpha = data.second; // Alpha value
165
166 if (alpha > 0) { // Only draw if there's some alpha
167 CRGB c = color;
168 c.nscale8(alpha); // Scale the color by the alpha value
169 frameBuffer.at(wrapped_pos.x, wrapped_pos.y) = c;
170 }
171 }
172 }
173 } else {
174 // None splat rendering, looks aweful.
175 vec2f pos_vec2f = corkscrew.at_no_wrap(pos);
176 vec2<u16> pos_i16 = vec2<u16>(round(pos_vec2f.x), round(pos_vec2f.y));
177 // Now map the cork screw position to the cylindrical buffer that we
178 // will draw.
179 frameBuffer.at(pos_i16.x, pos_i16.y) =
180 CRGB::Blue; // Draw a blue pixel at (w, h)
181 }
182 FastLED.show();
183}
uint8_t pos
Definition Blur.ino:11
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
uint16_t speed
Definition Noise.ino:63
Entry & at(u16 x, u16 y)
Definition tile2x2.cpp:65
UICheckbox cachingEnabled("Enable Tile Caching", true)
Corkscrew corkscrew(CORKSCREW_TURNS, NUM_LEDS)
UICheckbox splatRendering("Splat Rendering", true)
fl::Grid< CRGB > frameBuffer
Definition Corkscrew.h:104
UICheckbox allWhite("All White", false)
void clear(CRGB(&arr)[N])
Definition clear.h:13
vec2< float > vec2f
Definition geometry.h:333
CRGB & nscale8(fl::u8 scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
@ Blue
<div style='background:#0000FF;width:4em;height:4em;'></div>
Definition crgb.h:569
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
value_type y
Definition geometry.h:191
value_type x
Definition geometry.h:190
#define round(x)
Definition util.h:11

References allWhite(), fl::Tile2x2_u8_wrap::at(), CRGB::Blue, cachingEnabled(), fl::clear(), corkscrew(), FastLED, frameBuffer, CRGB::nscale8(), pos, round, speed, splatRendering(), fl::vec2< T >::x, and fl::vec2< T >::y.

+ Here is the call graph for this function: