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

◆ applyFancyEffect()

void applyFancyEffect ( uint32_t now,
bool button_active )

Definition at line 167 of file wavefx.cpp.

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