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

Function drawPlasmaWave

examples/Audio/advanced/advanced.h:432–455  ·  view source on GitHub ↗

Visualization: Plasma Wave

Source from the content-addressed store, hash-verified

430
431// Visualization: Plasma Wave
432void drawPlasmaWave(float peak) {
433 static float time = 0; // okay static in header
434 time += 0.05f + (peak * 0.2f);
435
436 fl::CRGBPalette16 palette = getCurrentPalette();
437
438 for (int x = 0; x < WIDTH; x++) {
439 for (int y = 0; y < HEIGHT; y++) {
440 float value = fl::sinf(x * 0.1f + time) +
441 fl::sinf(y * 0.1f - time) +
442 fl::sinf((x + y) * 0.1f + time) +
443 fl::sinf(fl::sqrtf(x * x + y * y) * 0.1f - time);
444
445 value = (value + 4) / 8; // Normalize to 0-1
446 value *= audioGain.value() * autoGainValue;
447
448 uint8_t colorIndex = value * 255;
449 int ledIndex = xyMap(x, y);
450 if (ledIndex >= 0 && ledIndex < NUM_LEDS) {
451 leds[ledIndex] = ColorFromPalette(palette, colorIndex + hue);
452 }
453 }
454 }
455}
456
457void setup() {
458 Serial.begin(115200);

Callers 1

loopFunction · 0.85

Calls 5

getCurrentPaletteFunction · 0.85
sinfFunction · 0.85
sqrtfFunction · 0.85
ColorFromPaletteFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected