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 auto shape = getShape(whichShape.as<int>());
125 shape->setScale(scale.value());
126
127 float curr_alpha = getAnimationTime(now_warped);
128 static float s_prev_alpha = 0.0f;
129
130 // unconditionally apply the circle.
131 if (trigger) {
132 // trigger the transition
133 time_warp.reset(now);
134 now_warped = time_warp.update(now);
135 shapeProgress.trigger(now_warped);
136 FASTLED_WARN("Transition triggered on " << shape->name());
137 curr_alpha = getAnimationTime(now_warped);
138 s_prev_alpha = curr_alpha;
139 }
140
141 // FASTLED_WARN("Current alpha: " << curr_alpha);
142 // FASTLED_WARN("maxAnimation: " << maxAnimation.value());
143
144 const bool is_active =
145 true || curr_alpha < maxAnimation.value() && curr_alpha > 0.0f;
146
147 // if (shapeProgress.isActive(now)) {
148 static uint32_t frame = 0;
149 frame++;
150 clearLeds();
151 const CRGB purple = CRGB(255, 0, 255);
152 const int number_of_steps = numberOfSteps.value();
153 raster.reset();
154 // float factor = s_prev_alpha; // 0->1.f
155 // factor = MIN(factor/4.0f, 0.05f);
156
157 float diff = curr_alpha - s_prev_alpha;
158 diff *= 1.0f;
159 float factor = MAX(s_prev_alpha - diff, 0.f);
160
161 for (int i = 0; i < number_of_steps; ++i) {
162 float a =
163 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
164 if (a < .04) {
165 // shorter tails at first.
166 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
167 }
168 float diff_max_alpha = maxAnimation.value() - curr_alpha;
169 if (diff_max_alpha < 0.94) {
170 // shorter tails at the end.
171 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
172 curr_alpha, maxAnimation.value());
173 }
174 uint8_t alpha =
175 fl::map_range<float>(i, 0.0f, number_of_steps - 1, 64, 255);
176 if (!is_active) {
177 alpha = 0;
178 }
179 Tile2x2_u8 subpixel = shape->at_subpixel(a);
180 subpixel.scale(alpha);
181 // subpixels.push_back(subpixel);
182 raster.rasterize(subpixel);
183 }
184
185 s_prev_alpha = curr_alpha;
186
187
188 if (useWaveFx && is_active) {
189 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
190 raster.draw(xyMap, draw_wave_fx);
191 } else {
192 raster.draw(purple, xyMap, leds);
193 }
194
195 int first = xyMap(1, 1);
196 int last = xyMap(WIDTH - 2, HEIGHT - 2);
197
198 leds[first] = CRGB(255, 0, 0);
199 leds[last] = CRGB(0, 255, 0);
200 if (useWaveFx) {
201 // fxBlend.draw(Fx::DrawContext(now, leds));
202 wave_fx.draw(Fx::DrawContext(now, leds));
203 }
204
205 EVERY_N_SECONDS(1) {
206 uint32_t frame_time = millis() - now;
207 FASTLED_WARN("Frame time: " << frame_time << "ms");
208 }
209
210 FastLED.show();
211}
CRGB leds[NUM_LEDS]
fl::XYMap xyMap
Definition ColorBoost.h:61
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
uint16_t scale
Definition Noise.ino:74
#define WIDTH
Definition advanced.h:36
#define HEIGHT
Definition advanced.h:37
_DrawContext DrawContext
Definition fx.h:21
void scale(u8 scale)
Definition tile2x2.cpp:43
void clearLeds()
Definition complex.h:116
XYPathPtr getShape(int which)
Definition complex.h:55
float getAnimationTime(uint32_t now)
Definition complex.h:111
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)
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1186
#define MAX(a, b)
Definition math_macros.h:37
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
#define FASTLED_WARN
Definition warn.h:7

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