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

◆ loop()

void loop ( )

Definition at line 132 of file Downscale.h.

132 {
133 // Your code here
134 clearLeds();
135 const uint32_t now = millis();
136 uint32_t now_warped = time_warp.update(now);
137
138 auto shape = getShape(whichShape.as<int>());
139 shape->setScale(scale.value());
140
141 float curr_alpha = getAnimationTime(now_warped);
142 static float s_prev_alpha = 0.0f;
143
144 // unconditionally apply the circle.
145 if (trigger) {
146 // trigger the transition
147 time_warp.reset(now);
148 now_warped = time_warp.update(now);
149 shapeProgress.trigger(now_warped);
150 FASTLED_WARN("Transition triggered on " << shape->name());
151 curr_alpha = getAnimationTime(now_warped);
152 s_prev_alpha = curr_alpha;
153 }
154
155 clearLeds();
156 const CRGB purple = CRGB(255, 0, 255);
157 const int number_of_steps = numberOfSteps.value();
158 raster.reset();
159
160 float diff = curr_alpha - s_prev_alpha;
161 diff *= 1.0f;
162 float factor = MAX(s_prev_alpha - diff, 0.f);
163
164 for (int i = 0; i < number_of_steps; ++i) {
165 float a =
166 fl::map_range<float>(i, 0, number_of_steps - 1, factor, curr_alpha);
167 if (a < .04) {
168 // shorter tails at first.
169 a = map_range<float>(a, 0.0f, .04f, 0.0f, .04f);
170 }
171 float diff_max_alpha = maxAnimation.value() - curr_alpha;
172 if (diff_max_alpha < 0.94) {
173 // shorter tails at the end.
174 a = map_range<float>(a, curr_alpha, maxAnimation.value(),
175 curr_alpha, maxAnimation.value());
176 }
177 uint8_t alpha =
178 fl::map_range<uint8_t>(i, 0.0f, number_of_steps - 1, 64, 255);
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 if (useWaveFx) {
188 DrawRasterToWaveSimulator draw_wave_fx(&wave_fx);
189 raster.draw(xyMap, draw_wave_fx);
190 } else {
191 raster.draw(purple, xyMap, leds);
192 }
193
194 int first = xyMap(1, 1);
195 int last = xyMap(WIDTH - 2, HEIGHT - 2);
196
197 leds[first] = CRGB(255, 0, 0);
198 leds[last] = CRGB(0, 255, 0);
199 if (useWaveFx) {
200 // fxBlend.draw(Fx::DrawContext(now, leds));
201 wave_fx.draw(Fx::DrawContext(now, leds));
202 }
203
204 // downscaleBilinear(leds, WIDTH, HEIGHT, leds_downscaled, WIDTH / 2,
205 // HEIGHT / 2);
206
208
209 // Print out the first 10 pixels of the original and downscaled
210 fl::vector_inlined<CRGB, 10> downscaled_pixels;
211 fl::vector_inlined<CRGB, 10> original_pixels;
212 for (int i = 0; i < 10; ++i) {
213 original_pixels.push_back(leds[i]);
214 downscaled_pixels.push_back(leds_downscaled[i]);
215 }
216
217 FastLED.show();
218}
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 push_back(const T &value)
Definition vector.h:1061
void scale(u8 scale)
Definition tile2x2.cpp:43
UISlider numberOfSteps("Number of Steps", 32.0f, 1.0f, 100.0f, 1.0f)
UIButton trigger("Trigger")
void clearLeds()
Definition Downscale.h:127
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:122
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)
#define MAX(a, b)
Definition math_macros.h:37
InlinedVector< T, INLINED_SIZE > vector_inlined
Definition vector.h:1220
void downscaleHalf(const CRGB *src, fl::u16 srcWidth, fl::u16 srcHeight, CRGB *dst)
Definition downscale.cpp:18
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
#define FASTLED_WARN
Definition warn.h:7

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