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

◆ applyFancyEffect()

void applyFancyEffect ( uint32_t now,
bool button_active )

Definition at line 168 of file wavefx.cpp.

168 {
169 // Calculate the total animation duration based on the speed slider
170 // Higher fancySpeed value = shorter duration (faster animation)
171 uint32_t total =
172 map(fancySpeed.as<uint32_t>(), 0, fancySpeed.getMax(), 1000, 100);
173
174 // Create a static TimeRamp to manage the animation timing
175 // TimeRamp handles the transition from start to end over time
176 static TimeRamp pointTransition = TimeRamp(total, 0, 0);
177
178 // If the button is active, start/restart the animation
179 if (button_active) {
180 pointTransition.trigger(now, total, 0, 0);
181 }
182
183 // If the animation isn't currently active, exit early
184 if (!pointTransition.isActive(now)) {
185 // no need to draw
186 return;
187 }
188
189 // Find the center of the display
190 int mid_x = WIDTH / 2;
191 int mid_y = HEIGHT / 2;
192
193 // Calculate the maximum distance from center (half the width)
194 int amount = WIDTH / 2;
195
196 // Calculate the start and end coordinates for the cross
197 int start_x = mid_x - amount; // Leftmost point
198 int end_x = mid_x + amount; // Rightmost point
199 int start_y = mid_y - amount; // Topmost point
200 int end_y = mid_y + amount; // Bottommost point
201
202 // Get the current animation progress (0-255)
203 int curr_alpha = pointTransition.update8(now);
204
205 // Map the animation progress to the four points of the expanding cross
206 // As curr_alpha increases from 0 to 255, these points move from center to edges
207 int left_x = map(curr_alpha, 0, 255, mid_x, start_x); // Center to left
208 int down_y = map(curr_alpha, 0, 255, mid_y, start_y); // Center to top
209 int right_x = map(curr_alpha, 0, 255, mid_x, end_x); // Center to right
210 int up_y = map(curr_alpha, 0, 255, mid_y, end_y); // Center to bottom
211
212 // Convert the 0-255 alpha to 0.0-1.0 range
213 float curr_alpha_f = curr_alpha / 255.0f;
214
215 // Calculate the wave height value - starts high and decreases as animation progresses
216 // This makes the waves stronger at the beginning of the animation
217 float valuef = (1.0f - curr_alpha_f) * fancyIntensity.value() / 255.0f;
218
219 // Calculate the width of the cross lines
220 int span = fancyParticleSpan.value() * WIDTH;
221
222 // Add wave energy along the four expanding lines of the cross
223 // Each line is a horizontal or vertical span of pixels
224
225 // Left-moving horizontal line
226 for (int x = left_x - span; x < left_x + span; x++) {
227 waveFxLower.addf(x, mid_y, valuef); // Add to lower layer
228 waveFxUpper.addf(x, mid_y, valuef); // Add to upper layer
229 }
230
231 // Right-moving horizontal line
232 for (int x = right_x - span; x < right_x + span; x++) {
233 waveFxLower.addf(x, mid_y, valuef);
234 waveFxUpper.addf(x, mid_y, valuef);
235 }
236
237 // Downward-moving vertical line
238 for (int y = down_y - span; y < down_y + span; y++) {
239 waveFxLower.addf(mid_x, y, valuef);
240 waveFxUpper.addf(mid_x, y, valuef);
241 }
242
243 // Upward-moving vertical line
244 for (int y = up_y - span; y < up_y + span; y++) {
245 waveFxLower.addf(mid_x, y, valuef);
246 waveFxUpper.addf(mid_x, y, valuef);
247 }
248}
#define WIDTH
Definition Blur2d.ino:9
#define HEIGHT
Definition Blur2d.ino:10
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:83
uint8_t update8(uint32_t now) override
Compute current 0–255 output based on how much time has elapsed since trigger().
bool isActive(uint32_t now) const override
void trigger(uint32_t now) override
Call this when you want to (re)start the ramp cycle.
long map(long x, long in_min, long in_max, long out_min, long out_max)
UISlider fancyParticleSpan("Fancy Particle Span", 0.06f, 0.01f, 0.2f, 0.01f)
WaveFx waveFxLower(xyRect, CreateArgsLower())
UISlider fancySpeed("Fancy Speed", 796, 0, 1000, 1)
UISlider fancyIntensity("Fancy Intensity", 32, 1, 255, 1)
WaveFx waveFxUpper(xyRect, CreateArgsUpper())

References fancyIntensity, fancyParticleSpan, fancySpeed, HEIGHT, fl::TimeRamp::isActive(), fl::TimeRamp::trigger(), fl::TimeRamp::update8(), waveFxLower, waveFxUpper, WIDTH, x, and y.

Referenced by wavefx_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: