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

Function applyFancyEffect

examples/Fx/FxWave2d/wavefx.cpp:176–256  ·  view source on GitHub ↗

Create a fancy cross-shaped effect that expands from the center

Source from the content-addressed store, hash-verified

174
175// Create a fancy cross-shaped effect that expands from the center
176void applyFancyEffect(uint32_t now, bool button_active) {
177 // Calculate the total animation duration based on the speed slider
178 // Higher fancySpeed value = shorter duration (faster animation)
179 uint32_t total =
180 map(fancySpeed.as<uint32_t>(), 0, fancySpeed.getMax(), 1000, 100);
181
182 // Create a static TimeRamp to manage the animation timing
183 // TimeRamp handles the transition from start to end over time
184 static fl::TimeRamp pointTransition = fl::TimeRamp(0, total, 0);
185
186 // If the button is active, start/restart the animation
187 if (button_active) {
188 pointTransition.trigger(now);
189 }
190
191 // If the animation isn't currently active, exit early
192 if (!pointTransition.isActive(now)) {
193 // no need to draw
194 return;
195 }
196
197 // Find the center of the display
198 int mid_x = WIDTH / 2;
199 int mid_y = HEIGHT / 2;
200
201 // Calculate the maximum distance from center (half the width)
202 int amount = WIDTH / 2;
203
204 // Calculate the start and end coordinates for the cross
205 int start_x = mid_x - amount; // Leftmost point
206 int end_x = mid_x + amount; // Rightmost point
207 int start_y = mid_y - amount; // Topmost point
208 int end_y = mid_y + amount; // Bottommost point
209
210 // Get the current animation progress (0-255)
211 int curr_alpha = pointTransition.update8(now);
212
213 // Map the animation progress to the four points of the expanding cross
214 // As curr_alpha increases from 0 to 255, these points move from center to edges
215 int left_x = map(curr_alpha, 0, 255, mid_x, start_x); // Center to left
216 int down_y = map(curr_alpha, 0, 255, mid_y, start_y); // Center to top
217 int right_x = map(curr_alpha, 0, 255, mid_x, end_x); // Center to right
218 int up_y = map(curr_alpha, 0, 255, mid_y, end_y); // Center to bottom
219
220 // Convert the 0-255 alpha to 0.0-1.0 range
221 float curr_alpha_f = curr_alpha / 255.0f;
222
223 // Calculate the wave height value - starts high and decreases as animation progresses
224 // This makes the waves stronger at the beginning of the animation
225 float valuef = (1.0f - curr_alpha_f) * fancyIntensity.value() / 255.0f;
226
227 // Calculate the width of the cross lines
228 int span = fancyParticleSpan.value() * WIDTH;
229
230 // Add wave energy along the four expanding lines of the cross
231 // Each line is a horizontal or vertical span of pixels
232
233 // Left-moving horizontal line

Callers 1

wavefx_loopFunction · 0.85

Calls 8

mapFunction · 0.85
TimeRampClass · 0.85
update8Method · 0.80
getMaxMethod · 0.45
triggerMethod · 0.45
isActiveMethod · 0.45
valueMethod · 0.45
addfMethod · 0.45

Tested by

no test coverage detected