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

◆ loop()

void loop ( )

Definition at line 112 of file complex.h.

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