Files
cube/fx_fest.cpp
mikeandClaude Opus 5.5 a8fee0e960 Regler „Effekt“: ein Parameter je Effekt (Tempo, Farbe, Empfindlichkeit, …)
- Tempo (66 Effekte): eigene Effekt-Uhr 0,25- bis 4-mal so schnell; bei
  mehr Tempo mehrere Rechenschritte pro Bild (aufwändige Effekte nur
  einer), bei weniger nicht in jedem Bild
- Farbe (Blitzlicht, Blaulicht, Geschenk, Fraktalwolken, Lampe): Farbton
  des fertigen Bilds drehen
- Empfindlichkeit (Musik): Pegel und Spektrum verstärken, Beat-Schwelle
- Eigene: Gewitter Blitze, Feuer Hitze, Regen Stärke, Schnee Dichte,
  Weihnachtsbaum Kugelfarbe
- Mitte 128 = ursprünglicher Effekt; Wert je Effekt im Flash
- API: param in /api/state, Parametername in /api/effects
- App: Regler „Effekt“ unter der Helligkeit (Titel antippen = Mitte),
  Schalter in einer Zeile, „Alle Kategorien“ heißt jetzt „Zufällig“

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:57:13 +01:00

203 lines
7.8 KiB
C++

// Kategorie Festtage: Weihnachten und Silvester
// (dazu Schnee, Glitzer und Feuerwerk aus effects.cpp)
#include "fx.h"
// --- Weihnachtsbaum: grüner Kegel über alle Etagen mit ein paar roten Kugeln -----
static bool isTree(int x, int y, int z) {
static const float RADIUS[] = {2.3f, 2.0f, 1.5f, 1.0f, 0.0f}; // 21, 13, 9, 5, 1 LEDs
return distAxis(x, y) <= RADIUS[z];
}
void renderTree(uint32_t now) {
static const uint8_t BAUBLES[][3] = {{4, 1, 0}, {1, 4, 0}, {0, 1, 0}, {3, 3, 1}, {2, 0, 1}, {1, 3, 2}, {3, 2, 3}};
FastLED.clear();
FOR_XYZ if (isTree(x, y, z)) at(x, y, z) = CRGB(0, highlight, 0);
for (uint8_t i = 0; i < 7; i++) {
uint8_t glow = 180 + scale8(sin8(now / 20 + i * 37), 75); // langsames Glimmen
at(BAUBLES[i][0], BAUBLES[i][1], BAUBLES[i][2]) = CHSV(fxParam - 128, 255, scale8(highlight, glow)); // Regler: Mitte = rot
}
}
// --- Adventskranz: grüner Kranz, die Kerzen gehen nacheinander an --------------
void renderWreath(uint32_t now) {
static const uint8_t CX[] = {1, 3, 3, 1}, CY[] = {1, 1, 3, 3};
static uint8_t flicker[4];
FastLED.clear();
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float d = distAxis(x, y);
if (d < 1 || d > 2.6f) continue;
bool berry = (x * 7 + y * 3) % 5 == 0;
uint8_t n = inoise8(x * 70, y * 70, now / 20);
at(x, y, 0) = berry ? CRGB(scale8(brightness, 220), 0, 0) : CRGB(CHSV(90, 255, scale8(brightness, 120 + n / 3)));
}
uint8_t lit = 1 + (now - fxStart) / 8000 % 4; // alle 8 s eine Kerze mehr
for (uint8_t i = 0; i < 4; i++) {
CRGB wax(scale8(brightness, 200), 0, brightness / 10);
at(CX[i], CY[i], 1) = at(CX[i], CY[i], 2) = wax;
if (i >= lit) continue;
flicker[i] = (flicker[i] * 3 + random8(140, 255)) / 4;
uint8_t f = scale8(highlight, flicker[i]);
at(CX[i], CY[i], 3) = CRGB(f, scale8(f, 140), scale8(f, 25));
at(CX[i], CY[i], 4) = CRGB(f / 6, f / 12, 0); // Schein über der Flamme
}
}
// --- Lichterkette: bunte Birnen winden sich als Spirale um den Würfel -----------
void renderFairyLights(uint32_t now) {
static const CRGB BULBS[] = {CRGB(255, 0, 0), CRGB(0, 200, 0), CRGB(0, 60, 255), CRGB(255, 160, 0), CRGB(200, 0, 200)};
uint32_t t = now - fxStart;
bool chase = t / 6000 % 2 == 0; // abwechselnd Lauflicht und Blinken
FastLED.clear();
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t i = 0; i < 16; i++) {
uint8_t x, y;
ringPos(i + z * 3, x, y); // pro Etage versetzt: eine Spirale
uint8_t k = z * 16 + i;
uint8_t v = chase ? 60 + scale8(sin8(k * 24 - t / 3), 195)
: ((k + t / 600) % 2 ? 255 : 50);
at(x, y, z) = CRGB(BULBS[k % 5]).nscale8(scale8(highlight, v));
}
}
// --- Countdown: 5 Etagen gehen im Sekundentakt aus, dann Explosion und Feuerwerk --
void renderCountdown(uint32_t now) {
static bool boom = false;
if (fresh) boom = false;
uint32_t t = (now - fxStart) % 15000;
if (t < 5000) {
fresh = false;
boom = false;
uint8_t layers = 5 - t / 1000;
uint16_t inSecond = t % 1000;
FastLED.clear();
FOR_XYZ {
if (z >= layers) continue;
if (z == layers - 1 && inSecond > 750) // oberste Etage blinkt, bevor sie ausgeht
at(x, y, z) = (inSecond / 80) % 2 ? CRGB(highlight, highlight, highlight) : CRGB::Black;
else
at(x, y, z) = CHSV(28 + z * 6, 200, min(255, brightness * 2));
}
} else {
if (!boom) {
boom = true;
triggerExplosion(frameNow); // Spezialeffekte laufen in echter Zeit
}
renderFireworks(now);
}
}
// --- Wunderkerze: sprüht Funken und brennt langsam von oben nach unten ab ------
void renderSparkler(uint32_t now) {
float burn = ((now - fxStart) % 20000) / 20000.0f;
float head = TOP - burn * 3.2f;
FastLED.clear();
for (uint8_t z = 0; z < NUM_LAYERS && z < head; z++) at(2, 2, z) = CRGB(brightness / 4, brightness / 4, brightness / 4); // Draht
CRGB gold(highlight, scale8(highlight, 190), scale8(highlight, 70));
for (uint8_t i = random8(2, 5); i > 0; i--)
spawnParticle(MID, MID, head, rnd(-0.16f, 0.16f), rnd(-0.16f, 0.16f), rnd(-0.06f, 0.16f),
random8(3) ? gold : CRGB(highlight, highlight, highlight));
moveParticles(0.01f, 0.9f, 22);
drawParticles();
uint8_t f = random8(180, 255);
plot(MID, MID, head, CRGB(scale8(highlight, f), scale8(highlight, f), scale8(highlight, f * 3 / 4)));
}
// --- Geschenk: Paket mit goldener Schleife, wechselt alle 8 s die Farbe ----------
void renderGift(uint32_t now) {
uint32_t t = now - fxStart;
uint8_t hue = (t / 8000) * 85; // rot, grün, blau ...
uint16_t inSlot = t % 8000;
uint8_t fade = inSlot < 1020 ? inSlot / 4 : 255; // in der ersten Sekunde überblenden
uint8_t v = min(255, brightness * 2);
CRGB box = blend(CRGB(CHSV(hue - 85, 255, v)), CRGB(CHSV(hue, 255, v)), fade);
FastLED.clear();
FOR_XYZ {
if (z == TOP) continue;
bool hull = x == 0 || x == TOP || y == 0 || y == TOP || z == 0 || z == TOP - 1;
if (!hull) continue;
bool ribbon = x == 2 || y == 2;
if (ribbon) {
uint8_t v = random8() < 8 ? 255 : 170; // glitzert
at(x, y, z) = CRGB(scale8(highlight, v), scale8(highlight, v * 3 / 4), 0);
} else {
at(x, y, z) = box;
}
}
// Schleife obendrauf
uint8_t pulse = 160 + scale8(sin8(t / 5), 95);
for (uint8_t i = 0; i < 5; i++) {
static const int8_t DX[] = {0, 1, -1, 0, 0}, DY[] = {0, 0, 0, 1, -1};
uint8_t v = scale8(highlight, i ? pulse : 255);
at(2 + DX[i], 2 + DY[i], TOP) = CRGB(v, scale8(v, 190), 0);
}
}
// --- Zuckerstange: rot-weiße Streifen drehen sich als Spirale nach oben ----------
void renderCandyCane(uint32_t now) {
float t = (now - fxStart) * 0.003f;
uint8_t v = min(255, brightness * 2);
CRGB red(v, 0, 0), white(scale8(v, 200), scale8(v, 200), scale8(v, 200));
FastLED.clear();
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t i = 0; i < 16; i++) {
uint8_t x, y;
ringPos(i, x, y);
float s = sinf((i + z * 2) * (TWO_PI / 8) - t);
at(x, y, z) = blend(red, white, uint8_t(smooth(s * 2 + 0.5f) * 255));
}
}
// --- Sekt: goldene Flüssigkeit, Perlen steigen auf ------------------------------
void renderBubbly(uint32_t now) {
float t = (now - fxStart) * 0.001f;
float level = 2.6f + 0.2f * sinf(t * 2);
FastLED.clear();
FOR_XYZ {
float f = constrain(level - z + 0.5f, 0.0f, 1.0f);
if (f > 0) at(x, y, z) = CRGB(brightness, scale8(brightness, 170), brightness / 8).nscale8(uint8_t(f * 255));
if (fabsf(z - level) < 0.6f && random8() < 30) at(x, y, z) += CRGB(brightness / 2, brightness / 2, brightness / 3); // Schaum
}
if (random8() < 70)
spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), 0, 0, 0, rnd(0.03f, 0.07f), CRGB(highlight, highlight, scale8(highlight, 150)));
for (Particle &p : particles) {
if (!p.life) continue;
p.vx = rnd(-0.01f, 0.01f);
p.vy = rnd(-0.01f, 0.01f);
if (p.z > level) p.life = 0; // an der Oberfläche geplatzt
}
moveParticles(0, 1, 0);
drawParticles();
}
// --- Weihnachtsstern: Strahlen in alle Richtungen, Achsen und Diagonalen im Wechsel --
void renderXmasStar(uint32_t now) {
uint32_t t = now - fxStart;
uint8_t swap = sin8(t / 20);
FastLED.clear();
FOR_XYZ {
int dx = abs(x - 2), dy = abs(y - 2), dz = abs(z - 2);
uint8_t nonzero = (dx > 0) + (dy > 0) + (dz > 0);
int m = max(max(dx, dy), dz);
bool axis = nonzero <= 1;
bool diagonal = nonzero >= 2 && (dx == 0 || dx == m) && (dy == 0 || dy == m) && (dz == 0 || dz == m);
if (!axis && !diagonal) continue;
float r = sqrtf(dx * dx + dy * dy + dz * dz);
uint8_t wave = sin8(wrap8(r * 50) - t / 4);
uint8_t mix = axis ? swap : 255 - swap;
uint8_t v = scale8(scale8(highlight, 90 + scale8(wave, 165)), mix);
at(x, y, z) = CRGB(v, scale8(v, 200), scale8(v, uint8_t(r * 50))); // außen weißlicher
}
at(2, 2, 2) = CRGB(highlight, highlight, highlight);
}