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

◆ loop()

void loop ( )

Definition at line 132 of file Corkscrew.h.

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

+ Here is the call graph for this function: