// Kategorie Festtage: Weihnachten und Silvester // (dazu Schnee, Glitzer und Feuerwerk aus effects.cpp) #include "fx.h" // --- Weihnachtsbaum: grüner Kegel mit Kugeln, Stern an der Spitze, leiser Schnee -- static bool isTree(int x, int y, int z) { float d = distAxis(x, y); switch (z) { case 1: return d <= 2.3f; // 21 LEDs case 2: return d <= 2.0f; // 13 LEDs case 3: return d <= 1.0f; // 5 LEDs default: return false; // unten Stamm, oben Stern } } struct Bauble { uint8_t x, y, z, phase; CRGB color; }; static Bauble baubles[10]; static void placeBauble(Bauble &b) { static const CRGB COLORS[] = {CRGB(255, 0, 0), CRGB(255, 170, 0), CRGB(0, 60, 255), CRGB(200, 0, 160), CRGB(255, 255, 255)}; do { b.x = random8(CUBE_SIZE); b.y = random8(CUBE_SIZE); b.z = random8(1, 4); } while (!isTree(b.x, b.y, b.z) || (b.x == 2 && b.y == 2 && b.z < 3)); // nicht im Stamm-Inneren b.color = COLORS[random8(5)]; b.phase = random8(); } void renderTree(uint32_t now) { static uint32_t lastMove = 0; if (fresh) { fresh = false; for (Bauble &b : baubles) placeBauble(b); lastMove = now; } if (now - lastMove > 1500) { // ab und zu wandert ein Licht lastMove = now; placeBauble(baubles[random8(10)]); } FastLED.clear(); at(2, 2, 0) = CRGB(brightness / 2, brightness / 5, 0); // Stamm FOR_XYZ { if (!isTree(x, y, z)) continue; uint8_t n = inoise8(x * 60, y * 60, z * 60 + now / 12); at(x, y, z) = CHSV(96, 255, scale8(brightness, 140 + n / 3)); } for (Bauble &b : baubles) { uint8_t v = 110 + scale8(sin8(now / 6 + b.phase), 145); at(b.x, b.y, b.z) = CRGB(b.color).nscale8(scale8(highlight, v)); } // Stern: Mitte hell und funkelnd, die Zacken abwechselnd uint8_t tw = sin8(now / 3); at(2, 2, TOP) = CRGB(highlight, scale8(highlight, 200), scale8(highlight, tw / 3)); for (uint8_t i = 0; i < 4; i++) { static const int8_t DX[] = {1, -1, 0, 0}, DY[] = {0, 0, 1, -1}; uint8_t v = scale8(highlight, 80 + scale8(sin8(now / 4 + i * 64), 120)); at(2 + DX[i], 2 + DY[i], TOP) = CRGB(v, scale8(v, 170), 0); } if (random8() < 4) at(2, 2, TOP) = CRGB::White; // leiser Schnee rundherum if (random8() < 6) spawnParticle(rnd(0, TOP), rnd(0, TOP), TOP + 0.4f, 0, 0, -rnd(0.015f, 0.025f), CRGB(brightness, brightness, brightness)); moveParticles(0, 1, 0); for (const Particle &p : particles) { int x = lroundf(p.x), y = lroundf(p.y), z = lroundf(p.z); if (p.life && !isTree(x, y, z) && !(x == 2 && y == 2)) plot(p.x, p.y, p.z, p.color); } } // --- 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(now); } 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); }