// Kategorie Ruhe: sehr ruhige, langsame Effekte #include "fx.h" // --- Atmen: der ganze Würfel wird langsam hell und wieder dunkel ---------------- void renderBreathe(uint32_t now) { uint32_t t = now - fxStart; float breath = (1 - cosf(t * (TWO_PI / 8000))) / 2; // ein Atemzug in 8 s uint8_t hue = 140 + t / 1000; // Farbe wandert sehr langsam FOR_XYZ { float d = dist3(x, y, z, MID, MID, MID); float v = (0.12f + 0.88f * breath) * (1 - d / 6); at(x, y, z) = CHSV(hue + wrap8(d * 6), 200, uint8_t(v * min(255, brightness * 2))); } } // --- Kerzenschein: eine Flamme in der Mitte, warmes Licht ringsum --------------- void renderCandle(uint32_t now) { static float flick = 1; flick += (rnd(0.65f, 1.0f) - flick) * 0.08f; // sanftes Flackern float fx = MID + (inoise8(now / 3) - 128) / 128.0f * 0.35f; float fy = MID + (inoise8(now / 3 + 9000) - 128) / 128.0f * 0.35f; FOR_XYZ { float d = dist3(x, y, z, fx, fy, 2.3f); float g = flick * min(255, brightness * 4) / (1 + d * d * 1.3f); at(x, y, z) = CRGB(g, g * 0.5f, g * 0.12f); } at(2, 2, 0) += CRGB(brightness / 3, brightness / 4, brightness / 5); // Kerze at(2, 2, 1) += CRGB(brightness / 3, brightness / 4, brightness / 5); } // --- Sternenhimmel: dunkelblau, die Sterne funkeln ganz langsam ---------------- struct Star { uint8_t x, y, z, phase, speed; CRGB color; }; static Star stars[20]; void renderStarrySky(uint32_t now) { if (fresh) { fresh = false; static const CRGB TINTS[] = {CRGB(255, 255, 255), CRGB(180, 200, 255), CRGB(255, 220, 170)}; for (Star &s : stars) s = {random8(CUBE_SIZE), random8(CUBE_SIZE), random8(NUM_LAYERS), random8(), random8(2, 6), TINTS[random8(3)]}; } FOR_XYZ at(x, y, z) = CRGB(0, 0, brightness / 14); for (const Star &s : stars) { uint8_t v = scale8(sin8(now * s.speed / 64 + s.phase), min(255, brightness * 2)); at(s.x, s.y, s.z) = CRGB(s.color).nscale8(v) + CRGB(0, 0, brightness / 14); } } // --- Mondlicht: blasser Mond, Wolken ziehen langsam vorbei ------------------- void renderMoonlight(uint32_t now) { uint32_t t = now - fxStart; FOR_XYZ { float d = dist3(x, y, z, 3.4f, 3.4f, 3.6f); float moon = constrain(1.6f - d, 0.0f, 1.0f); uint8_t cloud = qsub8(inoise8(x * 50 + t / 30, y * 50, z * 50 + t / 45), 110); // Wolken cloud = qadd8(cloud, cloud); CRGB c(0, 0, brightness / 10); // Nachthimmel c += CRGB(brightness, brightness, scale8(min(255, brightness * 2), 230)).nscale8(uint8_t(moon * scale8(255 - cloud, 255))); c += CRGB(brightness / 4, brightness / 4, brightness / 3).nscale8(cloud); // vom Mond beschienene Wolken if (z == 0) c += CRGB(0, 0, scale8(brightness / 3, sin8(x * 60 + y * 40 + t / 20))); // Wasser glitzert at(x, y, z) = c; } } // --- Farbwechsel: der ganze Würfel in einer Farbe, die sich ganz langsam ändert --- void renderColorCycle(uint32_t now) { uint32_t t = now - fxStart; FOR_XYZ at(x, y, z) = CHSV(t / 350 + z * 4, 210, brightness); // eine Runde in 90 s } // --- Glut: glimmende Holzkohle, dunkelrot bis orange --------------------------- void renderEmbers(uint32_t now) { uint32_t t = now - fxStart; FOR_XYZ { uint8_t n = inoise8(x * 60, y * 60 + t / 40, z * 60 - t / 30); uint8_t heat = scale8(n, 150 - z * 22); // unten heißer at(x, y, z) = HeatColor(heat).nscale8(min(255, brightness * 3)); } } // --- Tiefsee: Lichtflecken spielen langsam, ab und zu steigt eine Blase auf ------ void renderDeepSea(uint32_t now) { uint32_t t = now - fxStart; FOR_XYZ { uint8_t n = inoise8(x * 60 + t / 30, y * 60 + t / 40, z * 30 + t / 50); n = qsub8(n, 100); n = qadd8(n, n); uint8_t depth = 90 + z * 40; // oben heller at(x, y, z) = CHSV(150 + n / 16, 230, scale8(scale8(depth, 60 + n), min(255, brightness * 2))); } if (random8() < 3) spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), 0, 0, 0, rnd(0.01f, 0.02f), CRGB(brightness / 2, brightness, brightness)); for (Particle &p : particles) p.vx = p.life ? 0.004f * sinf(now * 0.002f + p.y) : 0; moveParticles(0, 1, 0); for (Particle &p : particles) if (p.life && p.z > TOP) p.life = 0; drawParticles(); } // --- Dämmerung: Abendrot unten, Nachtblau oben, die Farben verschieben sich langsam void renderDusk(uint32_t now) { static const CRGBPalette16 palette(CRGB(255, 80, 0), CRGB(200, 0, 60), CRGB(70, 0, 120), CRGB(0, 10, 60)); uint32_t t = now - fxStart; uint8_t shift = sin8(t / 240) / 4; // langsam hin und her FOR_XYZ { uint8_t n = inoise8(x * 40, y * 40, t / 25) / 8; at(x, y, z) = ColorFromPalette(palette, min(240, z * 55 + shift + n), brightness); } } // --- Gezeiten: der Wasserspiegel hebt und senkt sich langsam -------------------- void renderTide(uint32_t now) { float t = (now - fxStart) * 0.001f; float level = 2 + 1.6f * sinf(t * TWO_PI / 20); // Ebbe und Flut in 20 s FOR_XYZ { float ripple = 0.15f * sinf(x * 1.3f + t) * cosf(y * 1.1f - t * 0.8f); float f = constrain(level + ripple - z + 0.5f, 0.0f, 1.0f); float surface = constrain(1 - fabsf(level + ripple - z) * 1.5f, 0.0f, 1.0f); CRGB c = CHSV(150 - z * 3, 240, uint8_t(f * brightness)); c += CHSV(135, 120, uint8_t(surface * brightness)); at(x, y, z) = c; } } // --- Laternen: warme Lichter steigen langsam auf und verglimmen oben ------------- struct Lantern { float x, y, z, vz, phase; uint8_t hue; }; static Lantern lanterns[4]; static void newLantern(Lantern &l, bool anywhere) { l = {rnd(0.5f, TOP - 0.5f), rnd(0.5f, TOP - 0.5f), anywhere ? rnd(-1, TOP) : rnd(-3, -1), rnd(0.004f, 0.008f), rnd(0, TWO_PI), random8(15, 35)}; } void renderLanterns(uint32_t now) { if (fresh) { fresh = false; for (Lantern &l : lanterns) newLantern(l, true); } float t = (now - fxStart) * 0.001f; FastLED.clear(); for (Lantern &l : lanterns) { l.z += l.vz; if (l.z > TOP + 0.6f) newLantern(l, false); float fade = smooth((l.z + 1) / 1.5f) * smooth((TOP + 0.6f - l.z) / 1.5f); // unten auf-, oben abblenden float flick = 0.85f + 0.15f * sinf(t * 3 + l.phase); plotSoft(l.x + 0.4f * sinf(t * 0.4f + l.phase), l.y + 0.4f * cosf(t * 0.3f + l.phase), l.z, CHSV(l.hue, 230, uint8_t(fade * flick * highlight))); } } // --- Sanduhr: Sand rieselt Korn für Korn nach unten, dann wird umgedreht --------- static uint8_t sandOrder[2][50][3]; // Reihenfolge der Plätze: [oben/unten][Platz] = x, y, z static void sortCells(uint8_t cells[][3], bool top) { // oben: am Rand und unten bleibt Sand am längsten liegen; unten: Hügel von der Mitte aus uint8_t n = 0; float key[50]; for (uint8_t z = top ? 3 : 0; z < (top ? 5 : 2); z++) for (uint8_t y = 0; y < CUBE_SIZE; y++) for (uint8_t x = 0; x < CUBE_SIZE; x++) { float d = distAxis(x, y); key[n] = top ? z * 1.5f + (3 - d) : z * 1.5f + d; cells[n][0] = x; cells[n][1] = y; cells[n][2] = z; n++; } for (uint8_t i = 1; i < n; i++) // Einfügesortierung nach key for (uint8_t j = i; j > 0 && key[j] < key[j - 1]; j--) { float k = key[j]; key[j] = key[j - 1]; key[j - 1] = k; for (uint8_t c = 0; c < 3; c++) { uint8_t v = cells[j][c]; cells[j][c] = cells[j - 1][c]; cells[j - 1][c] = v; } } } void renderHourglass(uint32_t now) { const uint8_t GRAINS = 25; const uint16_t GRAIN_MS = 1200; static uint32_t runStart = 0; if (fresh) { fresh = false; sortCells(sandOrder[0], true); sortCells(sandOrder[1], false); runStart = now; } uint32_t t = now - runStart; if (t > GRAINS * GRAIN_MS + 2500) { // durchgelaufen: umdrehen, der Sand ist wieder oben runStart = now; t = 0; } uint8_t fallen = min(GRAINS, t / GRAIN_MS); CRGB sand(min(255, brightness * 3 / 2), min(255, brightness * 11 / 10), brightness * 2 / 5); FastLED.clear(); for (uint8_t i = 0; i < GRAINS - fallen; i++) at(sandOrder[0][i][0], sandOrder[0][i][1], sandOrder[0][i][2]) = sand; for (uint8_t i = 0; i < fallen; i++) at(sandOrder[1][i][0], sandOrder[1][i][1], sandOrder[1][i][2]) = sand; if (fallen < GRAINS) at(2, 2, 2) = CRGB(sand).nscale8(128 + scale8(sin8(t / 4), 127)); // rieselndes Korn in der Engstelle } // --- Pastell: sanfte Farbverläufe in hellen Tönen ziehen langsam durch ---------- void renderPastel(uint32_t now) { uint32_t t = now - fxStart; FOR_XYZ at(x, y, z) = CHSV(x * 8 + y * 12 + z * 16 + t / 300, 110, brightness); }