- Kategorien Flash, Festtage (Weihnachten + Silvester), Musik, Floating, Natur, Fraktal, Ruhe mit je 12 Effekten; 66 neue Effekte, u. a. Weihnachtsbaum, Adventskranz, Countdown, Vulkan, Polarlicht, Mandelbrot, Lorenz-Attraktor, Leben 3D, Hilbertkurve, Sanduhr, Kerzenschein - eine Datei je Kategorie (fx_*.cpp), gemeinsame Hilfen in fx.h (plotSoft, fresh/fxStart für den Effektstart, ringPos, wrap8) - Gewitter bleibt der Starteffekt (jetzt in Natur) - App: Farben für die neuen Kategorien - README-Tabellen und API-Beispiele angepasst Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
174 lines
5.6 KiB
C++
174 lines
5.6 KiB
C++
// Kategorie Floating: fließende, schwebende Effekte
|
|
// (dazu Regenbogen, Lavalampe, Sinuswelle und Doppelhelix aus effects.cpp)
|
|
|
|
#include "fx.h"
|
|
|
|
// --- Plasma: überlagerte Sinuswellen als fließendes Farbfeld --------------------
|
|
|
|
void renderPlasma(uint32_t now) {
|
|
float t = (now - fxStart) * 0.001f;
|
|
FOR_XYZ {
|
|
float v = sinf(x * 0.9f + t) + sinf(y * 0.8f - t * 1.3f) + sinf(z * 0.7f + t * 0.7f) +
|
|
sinf(dist3(x, y, z, MID + 1.5f * sinf(t * 0.6f), MID, MID) * 1.5f - t * 2);
|
|
at(x, y, z) = CHSV(wrap8(v * 40 + t * 20), 240, brightness);
|
|
}
|
|
}
|
|
|
|
// --- Seifenblasen: schillernde Kugelschalen steigen langsam auf ------------------
|
|
|
|
struct Bubble {
|
|
float x, y, z, r, vz, phase;
|
|
uint8_t hue;
|
|
};
|
|
static Bubble bubbles[3];
|
|
|
|
static void newBubble(Bubble &b, bool anywhere) {
|
|
b.r = rnd(1.0f, 1.8f);
|
|
b.x = rnd(1, 3);
|
|
b.y = rnd(1, 3);
|
|
b.z = anywhere ? rnd(-b.r, TOP) : -b.r - rnd(0, 2);
|
|
b.vz = rnd(0.008f, 0.015f);
|
|
b.phase = rnd(0, TWO_PI);
|
|
b.hue = random8();
|
|
}
|
|
|
|
void renderBubbles(uint32_t now) {
|
|
if (fresh) {
|
|
fresh = false;
|
|
for (Bubble &b : bubbles) newBubble(b, true);
|
|
}
|
|
float t = (now - fxStart) * 0.001f;
|
|
FastLED.clear();
|
|
for (Bubble &b : bubbles) {
|
|
b.z += b.vz;
|
|
float bx = b.x + 0.5f * sinf(t * 0.7f + b.phase), by = b.y + 0.5f * cosf(t * 0.5f + b.phase);
|
|
if (b.z - b.r > TOP + 0.5f) newBubble(b, false);
|
|
FOR_XYZ {
|
|
float d = dist3(x, y, z, bx, by, b.z);
|
|
float f = 1 - fabsf(d - b.r) / 0.7f;
|
|
if (f > 0) at(x, y, z) += CHSV(b.hue + wrap8((z - b.z) * 40 + t * 30), 170, uint8_t(f * highlight * 0.6f));
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Farbnebel: bunte Wolken ziehen durch den Würfel ---------------------------
|
|
|
|
void renderColorFog(uint32_t now) {
|
|
uint32_t t = now - fxStart;
|
|
FOR_XYZ {
|
|
uint8_t hue = inoise8(x * 45, y * 45 + t / 12, z * 45 + t / 9);
|
|
uint8_t v = inoise8(x * 35 + 5000, y * 35 - t / 14, z * 35 + t / 11);
|
|
v = qsub8(v, 70);
|
|
v = qadd8(v, v);
|
|
at(x, y, z) = CHSV(hue * 2 + t / 80, 230, scale8(v, min(255, brightness * 3)));
|
|
}
|
|
}
|
|
|
|
// --- Metabälle: drei weiche Farbkugeln, die ineinander verschmelzen -------------
|
|
|
|
void renderMetaballs(uint32_t now) {
|
|
float t = (now - fxStart) * 0.001f;
|
|
float px[3], py[3], pz[3];
|
|
CRGB col[3];
|
|
for (uint8_t i = 0; i < 3; i++) {
|
|
px[i] = MID + 1.7f * sinf(t * (0.5f + 0.13f * i) + i * 2);
|
|
py[i] = MID + 1.7f * sinf(t * (0.37f + 0.11f * i) + i);
|
|
pz[i] = MID + 1.7f * sinf(t * (0.43f + 0.07f * i) + i * 4);
|
|
col[i] = CHSV(wrap8(i * 85 + t * 8), 255, 255);
|
|
}
|
|
FOR_XYZ {
|
|
float sum = 0, r = 0, g = 0, b = 0;
|
|
for (uint8_t i = 0; i < 3; i++) {
|
|
float f = 1.2f / (sq(x - px[i]) + sq(y - py[i]) + sq(z - pz[i]) + 0.4f);
|
|
sum += f;
|
|
r += f * col[i].r;
|
|
g += f * col[i].g;
|
|
b += f * col[i].b;
|
|
}
|
|
float v = smooth((sum - 0.35f) * 1.5f) * min(255, brightness * 3) / 255.0f / sum;
|
|
at(x, y, z) = CRGB(min(255.0f, r * v), min(255.0f, g * v), min(255.0f, b * v));
|
|
}
|
|
}
|
|
|
|
// --- Wirbel: Farben drehen sich um die Mittelachse, oben schneller als unten -----
|
|
|
|
void renderVortex(uint32_t now) {
|
|
float t = (now - fxStart) * 0.001f;
|
|
FOR_XYZ {
|
|
float a = atan2f(y - MID, x - MID);
|
|
float r = distAxis(x, y);
|
|
float hue = a * (256 / TWO_PI) * 2 + r * 30 - t * (40 + z * 12);
|
|
at(x, y, z) = CHSV(wrap8(hue), 230, scale8(brightness, 140 + uint8_t(r * 40)));
|
|
}
|
|
}
|
|
|
|
// --- Schwerelos: Lichtpunkte treiben langsam durch den Raum und ziehen Spuren ----
|
|
|
|
struct Drifter {
|
|
float p[3], v[3];
|
|
uint8_t hue;
|
|
};
|
|
static Drifter drifters[6];
|
|
|
|
void renderWeightless(uint32_t now) {
|
|
if (fresh) {
|
|
fresh = false;
|
|
for (Drifter &d : drifters) {
|
|
for (uint8_t i = 0; i < 3; i++) {
|
|
d.p[i] = rnd(0.5f, TOP - 0.5f);
|
|
d.v[i] = rnd(-0.02f, 0.02f);
|
|
}
|
|
d.hue = random8();
|
|
}
|
|
}
|
|
fadeToBlackBy(leds, NUM_LEDS, 18);
|
|
for (Drifter &d : drifters) {
|
|
for (uint8_t i = 0; i < 3; i++) {
|
|
d.v[i] += rnd(-0.002f, 0.002f);
|
|
if (d.p[i] < 0.4f) d.v[i] += 0.003f; // weich vom Rand weg
|
|
if (d.p[i] > TOP - 0.4f) d.v[i] -= 0.003f;
|
|
d.v[i] = constrain(d.v[i], -0.03f, 0.03f);
|
|
d.p[i] += d.v[i];
|
|
}
|
|
if (random8() < 20) d.hue++;
|
|
plotSoft(d.p[0], d.p[1], d.p[2], CHSV(d.hue, 190, highlight));
|
|
}
|
|
}
|
|
|
|
// --- Schwebende Ringe: zwei Kreise kippen und drehen sich wie ein Kreisel -------
|
|
|
|
// Abstand eines Punkts von einem Kreis um die Mitte (Radius R, Normale n)
|
|
static float ringDistance(float x, float y, float z, const float n[3], float R) {
|
|
float v[3] = {x - MID, y - MID, z - MID};
|
|
float h = v[0] * n[0] + v[1] * n[1] + v[2] * n[2];
|
|
float q = sqrtf(max(0.0f, v[0] * v[0] + v[1] * v[1] + v[2] * v[2] - h * h));
|
|
return sqrtf(h * h + sq(q - R));
|
|
}
|
|
|
|
void renderRings3d(uint32_t now) {
|
|
float t = (now - fxStart) * 0.001f;
|
|
float a = t * 0.9f, b = t * 0.37f;
|
|
float n1[3] = {sinf(a) * cosf(b), sinf(a) * sinf(b), cosf(a)};
|
|
float n2[3] = {cosf(-a * 0.8f), sinf(-a * 0.8f) * cosf(b), sinf(-a * 0.8f) * sinf(b)};
|
|
FastLED.clear();
|
|
FOR_XYZ {
|
|
float f1 = 1 - ringDistance(x, y, z, n1, 1.9f) / 0.7f, f2 = 1 - ringDistance(x, y, z, n2, 1.9f) / 0.7f;
|
|
if (f1 > 0) at(x, y, z) += CHSV(wrap8(t * 20), 220, uint8_t(f1 * highlight));
|
|
if (f2 > 0) at(x, y, z) += CHSV(wrap8(t * 20 + 128), 220, uint8_t(f2 * highlight));
|
|
}
|
|
}
|
|
|
|
// --- Pendelwelle: 25 Pendel mit leicht verschiedenen Längen bilden Muster -------
|
|
// Nach 60 s schwingen alle wieder im Gleichtakt.
|
|
|
|
void renderPendulums(uint32_t now) {
|
|
float t = ((now - fxStart) % 60000) / 1000.0f;
|
|
FastLED.clear();
|
|
for (uint8_t z = 0; z < NUM_LAYERS; z++)
|
|
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
|
|
uint8_t k = z * CUBE_SIZE + x;
|
|
float y = MID + MID * cosf(TWO_PI * (20 + k) * t / 60);
|
|
plotSoft(x, y, z, CHSV(k * 10, 220, highlight));
|
|
}
|
|
}
|