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

◆ loop()

void loop ( )

Definition at line 122 of file BilinearCompression.ino.

122 {
123 // Your code here
124 clearLeds();
125 const uint32_t now = millis();
126 uint32_t now_warped = time_warp.update(now);
127
128 auto shape = getShape(whichShape.as<int>());
129 shape->setScale(scale.value());
130
131 float curr_alpha = getAnimationTime(now_warped);
132 static float s_prev_alpha = 0.0f;
133
134 // unconditionally apply the circle.
135 if (trigger) {
136 // trigger the transition
137 time_warp.reset(now);
138 now_warped = time_warp.update(now);
139 shapeProgress.trigger(now_warped);
140 FASTLED_WARN("Transition triggered on " << shape->name());
141 curr_alpha = getAnimationTime(now_warped);
142 s_prev_alpha = curr_alpha;
143 }
144
145 const bool is_active =
146 true || curr_alpha < maxAnimation.value() && curr_alpha > 0.0f;
147
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
155 float diff = curr_alpha - s_prev_alpha;
156 diff *= 1.0f;
157 float factor = MAX(s_prev_alpha - diff, 0.f);
158
159 for (int i = 0; i < number_of_steps; ++i) {
160 float a =
161 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
162 if (a < .04) {
163 // shorter tails at first.
164 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
165 }
166 float diff_max_alpha = maxAnimation.value() - curr_alpha;
167 if (diff_max_alpha < 0.94) {
168 // shorter tails at the end.
169 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
170 curr_alpha, maxAnimation.value());
171 }
172 uint8_t alpha =
173 fl::map_range<uint8_t>(i, 0.0f, number_of_steps - 1, 64, 255);
174 if (!is_active) {
175 alpha = 0;
176 }
177 Tile2x2_u8 subpixel = shape->at_subpixel(a);
178 subpixel.scale(alpha);
179 // subpixels.push_back(subpixel);
180 raster.rasterize(subpixel);
181 }
182
183 s_prev_alpha = curr_alpha;
184
185
186 if (useWaveFx && is_active) {
187 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
188 raster.draw(xyMap, draw_wave_fx);
189 } else {
190 raster.draw(purple, xyMap, leds);
191 }
192
193 int first = xyMap(1, 1);
194 int last = xyMap(WIDTH - 2, HEIGHT - 2);
195
196 leds[first] = CRGB(255, 0, 0);
197 leds[last] = CRGB(0, 255, 0);
198 if (useWaveFx) {
199 // fxBlend.draw(Fx::DrawContext(now, leds));
200 wave_fx.draw(Fx::DrawContext(now, leds));
201 }
202
203 // downscaleBilinear(leds, WIDTH, HEIGHT, leds_downscaled, WIDTH / 2,
204 // HEIGHT / 2);
205
207
208 // Print out the first 10 pixels of the original and downscaled
209 fl::vector_inlined<CRGB, 10> downscaled_pixels;
210 fl::vector_inlined<CRGB, 10> original_pixels;
211 for (int i = 0; i < 10; ++i) {
212 original_pixels.push_back(leds[i]);
213 downscaled_pixels.push_back(leds_downscaled[i]);
214 }
215
216 FastLED.show();
217}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
void clearLeds()
TimeClampedTransition shapeProgress(TIME_ANIMATION)
XYPathPtr getShape(int which)
XYMap xyMap_Dst(WIDTH/2, HEIGHT/2, false)
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
float getAnimationTime(uint32_t now)
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")
#define HEIGHT
CRGB leds_downscaled[NUM_LEDS/4]
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
_DrawContext DrawContext
Definition fx.h:21
void push_back(const T &value)
Definition vector.h:919
void scale(uint8_t scale)
Definition tile2x2.cpp:24
#define MAX(a, b)
Definition math_macros.h:11
InlinedVector< T, INLINED_SIZE > vector_inlined
Definition vector.h:1034
void downscaleHalf(const CRGB *src, uint16_t srcWidth, uint16_t srcHeight, CRGB *dst)
Definition downscale.cpp:17
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(), fl::downscaleHalf(), FastLED, FASTLED_WARN, getAnimationTime(), getShape(), HEIGHT, leds, leds_downscaled, fl::map_range(), MAX, maxAnimation, numberOfSteps, fl::InlinedVector< T, INLINED_SIZE >::push_back(), raster, fl::Tile2x2_u8::scale(), scale, shapeProgress, time_warp, trigger, useWaveFx, wave_fx, whichShape, WIDTH, xyMap, and xyMap_Dst.

+ Here is the call graph for this function: