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

◆ loop()

void loop ( )

Definition at line 118 of file complex.h.

118 {
119 // Your code here
120 clearLeds();
121 const uint32_t now = millis();
122 uint32_t now_warped = time_warp.update(now);
123
124 // Apply UI stencil choice to both wave layers.
128 wave_fx.wave_fx_low->setStencil(stencil);
129 wave_fx.wave_fx_high->setStencil(stencil);
130
131 auto shape = getShape(whichShape.as<int>());
132 shape->setScale(scale.value());
133
134 float curr_alpha = getAnimationTime(now_warped);
135 static float s_prev_alpha = 0.0f; // okay static in header
136
137 // unconditionally apply the circle.
138 if (trigger) {
139 // trigger the transition
140 time_warp.reset(now);
141 now_warped = time_warp.update(now);
142 shapeProgress.trigger(now_warped);
143 FL_WARN("Transition triggered on " << shape->name());
144 curr_alpha = getAnimationTime(now_warped);
145 s_prev_alpha = curr_alpha;
146 }
147
148 // FL_WARN("Current alpha: " << curr_alpha);
149 // FL_WARN("maxAnimation: " << maxAnimation.value());
150
151 const bool is_active =
152 true || curr_alpha < maxAnimation.value() && curr_alpha > 0.0f;
153
154 // if (shapeProgress.isActive(now)) {
155 static uint32_t frame = 0;
156 frame++;
157 clearLeds();
158 const fl::CRGB purple = fl::CRGB(255, 0, 255);
159 const int number_of_steps = numberOfSteps.value();
160 raster.reset();
161 // float factor = s_prev_alpha; // 0->1.f
162 // factor = fl::min(factor/4.0f, 0.05f);
163
164 float diff = curr_alpha - s_prev_alpha;
165 diff *= 1.0f;
166 float factor = fl::max(s_prev_alpha - diff, 0.f);
167
168 for (int i = 0; i < number_of_steps; ++i) {
169 float a =
170 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
171 if (a < .04) {
172 // shorter tails at first.
173 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
174 }
175 float diff_max_alpha = maxAnimation.value() - curr_alpha;
176 if (diff_max_alpha < 0.94) {
177 // shorter tails at the end.
178 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
179 curr_alpha, maxAnimation.value());
180 }
181 uint8_t alpha =
182 fl::map_range<float>(i, 0.0f, number_of_steps - 1, 64, 255);
183 if (!is_active) {
184 alpha = 0;
185 }
186 fl::Tile2x2_u8 subpixel = shape->at_subpixel(a);
187 subpixel.scale(alpha);
188 // subpixels.push_back(subpixel);
189 raster.rasterize(subpixel);
190 }
191
192 s_prev_alpha = curr_alpha;
193
194
195 if (useWaveFx && is_active) {
196 fl::DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
197 raster.draw(xyMap, draw_wave_fx);
198 } else {
199 raster.draw(purple, xyMap, leds);
200 }
201
202 int first = xyMap(1, 1);
203 int last = xyMap(WIDTH - 2, HEIGHT - 2);
204
205 leds[first] = fl::CRGB(255, 0, 0);
206 leds[last] = fl::CRGB(0, 255, 0);
207 if (useWaveFx) {
208 // fxBlend.draw(fl::Fx::DrawContext(now, leds));
209 wave_fx.draw(fl::Fx::DrawContext(now, leds));
210 }
211
212 EVERY_N_SECONDS(1) {
213 uint32_t frame_time = millis() - now;
214 FL_WARN("Frame time: " << frame_time << "ms");
215 }
216
217 FastLED.show();
218}
fl::XYMap xyMap
fl::CRGB leds[NUM_LEDS]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::UISlider scale("Scale", 4,.1, 4,.1)
#define WIDTH
#define HEIGHT
::fl::DrawContext DrawContext
Definition fx.h:21
void scale(u8 scale)
fl::XYPathPtr getShape(int which)
Definition complex.h:54
void clearLeds()
Definition complex.h:116
float getAnimationTime(uint32_t now)
Definition complex.h:111
fl::UICheckbox useWaveFx("Use WaveFX", true)
fl::XYRaster raster(WIDTH, HEIGHT)
fl::TimeWarp time_warp
Definition Downscale.h:52
fl::UIButton trigger("Trigger")
WaveEffect wave_fx
Definition Downscale.h:48
fl::TimeClampedTransition shapeProgress(TIME_ANIMATION)
fl::UISlider maxAnimation("Max Animation", 1.0f, 5.0f, 20.0f, 1.f)
fl::UICheckbox isotropicStencil("Isotropic stencil (rounder ripples)", false)
fl::UISlider whichShape("Which Shape", 0.0f, 0.0f, shapes.size() - 1, 1.0f)
fl::UISlider numberOfSteps("Number of Steps", 32.0f, 1.0f, 100.0f, 1.0f)
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1010
#define FL_WARN(X)
Definition log.h:276
fl::CRGB CRGB
Definition video.h:15
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max) FL_NOEXCEPT
Definition math.h:174
unsigned char uint8_t
Definition s16x16x4.h:209
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References clearLeds(), EVERY_N_SECONDS, FastLED, fl::FivePoint, FL_WARN, getAnimationTime(), getShape(), HEIGHT, isotropicStencil(), leds, fl::map_range(), fl::max(), maxAnimation(), fl::NinePointIsotropic, numberOfSteps(), raster(), fl::Tile2x2_u8::scale(), scale, shapeProgress(), time_warp, trigger(), useWaveFx(), wave_fx, whichShape(), WIDTH, and xyMap.

+ Here is the call graph for this function: