MCPcopy Create free account
hub / github.com/FastLED/FastLED / loop

Function loop

examples/Downscale/Downscale.h:131–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129};
130
131void loop() {
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.
138 const fl::LaplacianStencil stencil = isotropicStencil
139 ? fl::LaplacianStencil::NinePointIsotropic
140 : fl::LaplacianStencil::FivePoint;
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);

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
DrawContextClass · 0.85
downscaleHalfFunction · 0.85
clearLedsFunction · 0.70
getShapeFunction · 0.70
getAnimationTimeFunction · 0.70
millisFunction · 0.50
CRGBClass · 0.50
updateMethod · 0.45
setStencilMethod · 0.45
setScaleMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected