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

◆ loop()

void loop ( )

Definition at line 128 of file Downscale.h.

128 {
129 // Your code here
130 clearLeds();
131 const uint32_t now = millis();
132 uint32_t now_warped = time_warp.update(now);
133
134 auto shape = getShape(whichShape.as<int>());
135 shape->setScale(scale.value());
136
137 float curr_alpha = getAnimationTime(now_warped);
138 static float s_prev_alpha = 0.0f;
139
140 // unconditionally apply the circle.
141 if (trigger) {
142 // trigger the transition
143 time_warp.reset(now);
144 now_warped = time_warp.update(now);
145 shapeProgress.trigger(now_warped);
146 FASTLED_WARN("Transition triggered on " << shape->name());
147 curr_alpha = getAnimationTime(now_warped);
148 s_prev_alpha = curr_alpha;
149 }
150
151 static uint32_t frame = 0;
152 frame++;
153 clearLeds();
154 const CRGB purple = CRGB(255, 0, 255);
155 const int number_of_steps = numberOfSteps.value();
156 raster.reset();
157
158 float diff = curr_alpha - s_prev_alpha;
159 diff *= 1.0f;
160 float factor = MAX(s_prev_alpha - diff, 0.f);
161
162 for (int i = 0; i < number_of_steps; ++i) {
163 float a =
164 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
165 if (a < .04) {
166 // shorter tails at first.
167 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
168 }
169 float diff_max_alpha = maxAnimation.value() - curr_alpha;
170 if (diff_max_alpha < 0.94) {
171 // shorter tails at the end.
172 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
173 curr_alpha, maxAnimation.value());
174 }
175 uint8_t alpha =
176 fl::map_range<uint8_t>(i, 0.0f, number_of_steps - 1, 64, 255);
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 if (useWaveFx) {
186 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
187 raster.draw(xyMap, draw_wave_fx);
188 } else {
189 raster.draw(purple, xyMap, leds);
190 }
191
192 int first = xyMap(1, 1);
193 int last = xyMap(WIDTH - 2, HEIGHT - 2);
194
195 leds[first] = CRGB(255, 0, 0);
196 leds[last] = CRGB(0, 255, 0);
197 if (useWaveFx) {
198 // fxBlend.draw(Fx::DrawContext(now, leds));
199 wave_fx.draw(Fx::DrawContext(now, leds));
200 }
201
202 // downscaleBilinear(leds, WIDTH, HEIGHT, leds_downscaled, WIDTH / 2,
203 // HEIGHT / 2);
204
206
207 // Print out the first 10 pixels of the original and downscaled
208 fl::vector_inlined<CRGB, 10> downscaled_pixels;
209 fl::vector_inlined<CRGB, 10> original_pixels;
210 for (int i = 0; i < 10; ++i) {
211 original_pixels.push_back(leds[i]);
212 downscaled_pixels.push_back(leds_downscaled[i]);
213 }
214
215 FastLED.show();
216}
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 push_back(const T &value)
Definition vector.h:965
void scale(uint8_t scale)
Definition tile2x2.cpp:35
UISlider numberOfSteps("Number of Steps", 32.0f, 1.0f, 100.0f, 1.0f)
UIButton trigger("Trigger")
void clearLeds()
Definition Downscale.h:123
XYPathPtr getShape(int which)
Definition Downscale.h:56
UISlider maxAnimation("Max Animation", 1.0f, 5.0f, 20.0f, 1.f)
WaveEffect wave_fx
Definition Downscale.h:50
XYMap xyMap_Dst(WIDTH/2, HEIGHT/2, false)
TimeWarp time_warp
Definition Downscale.h:54
float getAnimationTime(uint32_t now)
Definition Downscale.h:118
XYRaster raster(WIDTH, HEIGHT)
TimeClampedTransition shapeProgress(TIME_ANIMATION)
UICheckbox useWaveFx("Use WaveFX", true)
CRGB leds_downscaled[NUM_LEDS/4]
Definition Downscale.h:40
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 MAX(a, b)
Definition math_macros.h:11
InlinedVector< T, INLINED_SIZE > vector_inlined
Definition vector.h:1080
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: