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

◆ loop()

void loop ( )

Definition at line 131 of file Downscale.h.

131 {
132 // Your code here
133 clearLeds();
134 const uint32_t now = fl::millis();
135 uint32_t now_warped = time_warp.update(now);
136
137 // Apply UI stencil choice to both wave layers.
141 wave_fx.wave_fx_low->setStencil(stencil);
142 wave_fx.wave_fx_high->setStencil(stencil);
143
144 auto shape = getShape(whichShape.as<int>());
145 shape->setScale(scale.value());
146
147 float curr_alpha = getAnimationTime(now_warped);
148 static float s_prev_alpha = 0.0f; // okay static in header
149
150 // unconditionally apply the circle.
151 if (trigger) {
152 // trigger the transition
153 time_warp.reset(now);
154 now_warped = time_warp.update(now);
155 shapeProgress.trigger(now_warped);
156 FL_WARN("Transition triggered on " << shape->name());
157 curr_alpha = getAnimationTime(now_warped);
158 s_prev_alpha = curr_alpha;
159 }
160
161 clearLeds();
162 const fl::CRGB purple = fl::CRGB(255, 0, 255);
163 const int number_of_steps = numberOfSteps.value();
164 raster.reset();
165
166 float diff = curr_alpha - s_prev_alpha;
167 diff *= 1.0f;
168 float factor = fl::max(s_prev_alpha - diff, 0.f);
169
170 for (int i = 0; i < number_of_steps; ++i) {
171 float a =
172 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
173 if (a < .04) {
174 // shorter tails at first.
175 a = fl::map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
176 }
177 float diff_max_alpha = maxAnimation.value() - curr_alpha;
178 if (diff_max_alpha < 0.94) {
179 // shorter tails at the end.
180 a = fl::map_range<float>(a, curr_alpha, maxAnimation.value(),
181 curr_alpha, maxAnimation.value());
182 }
183 uint8_t alpha =
184 fl::map_range<uint8_t>(i, 0.0f, number_of_steps - 1, 64, 255);
185 fl::Tile2x2_u8 subpixel = shape->at_subpixel(a);
186 subpixel.scale(alpha);
187 // subpixels.push_back(subpixel);
188 raster.rasterize(subpixel);
189 }
190
191 s_prev_alpha = curr_alpha;
192
193 if (useWaveFx) {
194 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
195 raster.draw(xyMap, draw_wave_fx);
196 } else {
197 raster.draw(purple, xyMap, leds);
198 }
199
200 int first = xyMap(1, 1);
201 int last = xyMap(WIDTH - 2, HEIGHT - 2);
202
203 leds[first] = fl::CRGB(255, 0, 0);
204 leds[last] = fl::CRGB(0, 255, 0);
205 if (useWaveFx) {
206 // fxBlend.draw(fl::Fx::DrawContext(now, leds));
207 wave_fx.draw(fl::Fx::DrawContext(now, leds));
208 }
209
210 // downscaleBilinear(leds, WIDTH, HEIGHT, leds_downscaled, WIDTH / 2,
211 // HEIGHT / 2);
212
214
215 // Print out the first 10 pixels of the original and downscaled
216 fl::vector_inlined<fl::CRGB, 10> downscaled_pixels;
217 fl::vector_inlined<fl::CRGB, 10> original_pixels;
218 for (int i = 0; i < 10; ++i) {
219 original_pixels.push_back(leds[i]);
220 downscaled_pixels.push_back(leds_downscaled[i]);
221 }
222
223 FastLED.show();
224}
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)
void push_back(const T &value) FL_NOEXCEPT
Definition vector.h:624
fl::XYPathPtr getShape(int which)
Definition Downscale.h:54
fl::UICheckbox useWaveFx("Use WaveFX", true)
fl::XYMap xyMap_Dst(WIDTH/2, HEIGHT/2, false)
fl::XYRaster raster(WIDTH, HEIGHT)
void clearLeds()
Definition Downscale.h:126
fl::CRGB leds_downscaled[NUM_LEDS/4]
Definition Downscale.h:38
fl::TimeWarp time_warp
Definition Downscale.h:52
fl::UIButton trigger("Trigger")
WaveEffect wave_fx
Definition Downscale.h:48
fl::TimeClampedTransition shapeProgress(TIME_ANIMATION)
float getAnimationTime(uint32_t now)
Definition Downscale.h:121
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 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
void downscaleHalf(const CRGB *src, fl::u16 srcWidth, fl::u16 srcHeight, CRGB *dst)
VectorN< T, INLINED_SIZE > vector_inlined
Definition vector.h:1133
unsigned char uint8_t
Definition s16x16x4.h:209
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38

References clearLeds(), FastLED, fl::FivePoint, FL_WARN, getAnimationTime(), getShape(), HEIGHT, isotropicStencil(), leds, leds_downscaled, fl::map_range(), fl::max(), maxAnimation(), fl::millis(), fl::NinePointIsotropic, numberOfSteps(), fl::vector< T >::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: