#pragma once // Gemeinsame Hilfen für die Effekte (effects.cpp und fx_*.cpp) #include "cube.h" constexpr float MID = (CUBE_SIZE - 1) / 2.0f; // Mitte des Würfels // Schleife über alle LEDs: z = Etage, x/y = Position in der Etage #define FOR_XYZ \ for (uint8_t z = 0; z < NUM_LAYERS; z++) \ for (uint8_t y = 0; y < CUBE_SIZE; y++) \ for (uint8_t x = 0; x < CUBE_SIZE; x++) // true im ersten Bild nach einem Effektwechsel: Effekte mit eigenem Zustand // setzen ihn dann zurück und schreiben fresh = false. extern bool fresh; extern uint32_t fxStart; // effectClock beim Effektwechsel (Zeit des Effekts, siehe renderEffect) float rnd(float a, float b); // Zufallszahl a..b void plot(float x, float y, float z, const CRGB &c); // nächste LED, addiert void plotSoft(float x, float y, float z, const CRGB &c); // auf die 8 Nachbar-LEDs verteilt inline bool inCube(int x, int y, int z) { return x >= 0 && y >= 0 && z >= 0 && x < CUBE_SIZE && y < CUBE_SIZE && z < NUM_LAYERS; } inline float dist3(float x, float y, float z, float cx, float cy, float cz) { return sqrtf(sq(x - cx) + sq(y - cy) + sq(z - cz)); } // Abstand von der senkrechten Mittelachse inline float distAxis(float x, float y) { return hypotf(x - MID, y - MID); } // Größter Abstand zur Mitte je Achse: 0 = Mitte, 1 = innere Schale, 2 = Außenhaut inline uint8_t shell(uint8_t x, uint8_t y, uint8_t z) { return max(max(abs(x - 2), abs(y - 2)), abs(z - 2)); } // Die 16 LEDs am Rand einer Etage, im Kreis herum (i = 0..15) inline void ringPos(uint8_t i, uint8_t &x, uint8_t &y) { i %= 16; if (i < 4) { x = i; y = 0; } else if (i < 8) { x = 4; y = i - 4; } else if (i < 12) { x = 12 - i; y = 4; } else { x = 0; y = 16 - i; } } // Kommazahl als Farbton: läuft wie uint8_t über (direktes uint8_t(f) wäre außerhalb 0..255 undefiniert) inline uint8_t wrap8(float f) { return uint8_t(int32_t(f)); } // Weiche Ein-/Ausblendkurve 0..1 -> 0..1 inline float smooth(float t) { t = constrain(t, 0.0f, 1.0f); return t * t * (3 - 2 * t); } // --- Partikel (gemeinsamer Vorrat, wird beim Effektwechsel geleert) ---------- struct Particle { float x, y, z, vx, vy, vz; CRGB color; uint8_t life; // 0 = frei, sonst Helligkeit }; const uint8_t MAX_PARTICLES = 48; extern Particle particles[MAX_PARTICLES]; void spawnParticle(float x, float y, float z, float vx, float vy, float vz, const CRGB &color); void moveParticles(float gravity, float drag, uint8_t fade); void drawParticles();