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

◆ loop()

void loop ( )

Definition at line 117 of file complex.h.

117 {
118 // Your code here
119 clearLeds();
120 const uint32_t now = millis();
121 uint32_t now_warped = time_warp.update(now);
122
123 auto shape = getShape(whichShape.as<int>());
124 shape->setScale(scale.value());
125
126 float curr_alpha = getAnimationTime(now_warped);
127 static float s_prev_alpha = 0.0f;
128
129 // unconditionally apply the circle.
130 if (trigger) {
131 // trigger the transition
132 time_warp.reset(now);
133 now_warped = time_warp.update(now);
134 shapeProgress.trigger(now_warped);
135 FASTLED_WARN("Transition triggered on " << shape->name());
136 curr_alpha = getAnimationTime(now_warped);
137 s_prev_alpha = curr_alpha;
138 }
139
140 // FASTLED_WARN("Current alpha: " << curr_alpha);
141 // FASTLED_WARN("maxAnimation: " << maxAnimation.value());
142
143 const bool is_active =
144 true || curr_alpha < maxAnimation.value() && curr_alpha > 0.0f;
145
146 // if (shapeProgress.isActive(now)) {
147 static uint32_t frame = 0;
148 frame++;
149 clearLeds();
150 const CRGB purple = CRGB(255, 0, 255);
151 const int number_of_steps = numberOfSteps.value();
152 raster.reset();
153 // float factor = s_prev_alpha; // 0->1.f
154 // factor = MIN(factor/4.0f, 0.05f);
155
156 float diff = curr_alpha - s_prev_alpha;
157 diff *= 1.0f;
158 float factor = MAX(s_prev_alpha - diff, 0.f);
159
160 for (int i = 0; i < number_of_steps; ++i) {
161 float a =
162 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
163 if (a < .04) {
164 // shorter tails at first.
165 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
166 }
167 float diff_max_alpha = maxAnimation.value() - curr_alpha;
168 if (diff_max_alpha < 0.94) {
169 // shorter tails at the end.
170 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
171 curr_alpha, maxAnimation.value());
172 }
173 uint8_t alpha =
174 fl::map_range<float>(i, 0.0f, number_of_steps - 1, 64, 255);
175 if (!is_active) {
176 alpha = 0;
177 }
178 Tile2x2_u8 subpixel = shape->at_subpixel(a);
179 subpixel.scale(alpha);
180 // subpixels.push_back(subpixel);
181 raster.rasterize(subpixel);
182 }
183
184 s_prev_alpha = curr_alpha;
185
186
187 if (useWaveFx && is_active) {
188 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
189 raster.draw(xyMap, draw_wave_fx);
190 } else {
191 raster.draw(purple, xyMap, leds);
192 }
193
194 int first = xyMap(1, 1);
195 int last = xyMap(WIDTH - 2, HEIGHT - 2);
196
197 leds[first] = CRGB(255, 0, 0);
198 leds[last] = CRGB(0, 255, 0);
199 if (useWaveFx) {
200 // fxBlend.draw(Fx::DrawContext(now, leds));
201 wave_fx.draw(Fx::DrawContext(now, leds));
202 }
203
204 EVERY_N_SECONDS(1) {
205 uint32_t frame_time = millis() - now;
206 FASTLED_WARN("Frame time: " << frame_time << "ms");
207 }
208
209 FastLED.show();
210}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
Definition Blur2d.ino:9
#define HEIGHT
Definition Blur2d.ino:10
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:62
_DrawContext DrawContext
Definition fx.h:21
void scale(uint8_t scale)
Definition tile2x2.cpp:35
void clearLeds()
Definition complex.h:115
XYPathPtr getShape(int which)
Definition complex.h:54
float getAnimationTime(uint32_t now)
Definition complex.h:110
UISlider numberOfSteps("Number of Steps", 32.0f, 1.0f, 100.0f, 1.0f)
UIButton trigger("Trigger")
UISlider maxAnimation("Max Animation", 1.0f, 5.0f, 20.0f, 1.f)
WaveEffect wave_fx
Definition Downscale.h:50
TimeWarp time_warp
Definition Downscale.h:54
XYRaster raster(WIDTH, HEIGHT)
TimeClampedTransition shapeProgress(TIME_ANIMATION)
UICheckbox useWaveFx("Use WaveFX", true)
UISlider whichShape("Which Shape", 0.0f, 0.0f, shapes.size() - 1, 1.0f)
uint16_t scale
Definition funky.cpp:83
XYMap xyMap
Definition gfx.cpp:8
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1306
#define MAX(a, b)
Definition math_macros.h:11
FASTLED_FORCE_INLINE U map_range(T value, T in_min, T in_max, U out_min, U out_max)
Definition map_range.h:26
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
#define FASTLED_WARN
Definition warn.h:7

References clearLeds(), EVERY_N_SECONDS, FastLED, FASTLED_WARN, getAnimationTime(), getShape(), HEIGHT, leds, fl::map_range(), MAX, maxAnimation(), 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: