// Efeito Fibonacci Áurea 3D - Cubo 8x8x8
// Espirais e padrões áureos em 3 dimensões
#include <FastLED.h>
#define CUBE_SIZE 8
#define NUM_LEDS (CUBE_SIZE * CUBE_SIZE * CUBE_SIZE)
CRGB leds[NUM_LEDS];
// Paleta suave com transições naturais
CRGBPalette16 currentPalette = CRGBPalette16(
CRGB::DarkBlue, CRGB::DarkCyan,
CRGB::Teal, CRGB::Green,
CRGB::YellowGreen, CRGB::Orange,
CRGB::OrangeRed, CRGB::Red,
CRGB::DeepPink, CRGB::Purple,
CRGB::DarkViolet, CRGB::Blue,
CRGB::Navy, CRGB::DarkBlue,
CRGB::MidnightBlue,CRGB::DarkBlue
);
// Constantes da proporção áurea
#define PHI 1.618033988749895
#define PHI_INV 0.618033988749895
#define TWO_PI 6.283185307179586
void setup() {
FastLED.addLeds<NEOPIXEL, 3>(leds, NUM_LEDS);
FastLED.setBrightness(255);
FastLED.setMaxRefreshRate(120);
}
// Mapeamento XYZ para índice linear
// Ajuste conforme seu cabeamento do cubo
uint16_t XYZ(uint8_t x, uint8_t y, uint8_t z) {
if (x >= CUBE_SIZE || y >= CUBE_SIZE || z >= CUBE_SIZE)
return NUM_LEDS;
// Exemplo: camadas Z empilhadas, serpentina em Y
uint16_t index = z * CUBE_SIZE * CUBE_SIZE;
if (y & 0x01) {
// Linhas ímpares: direita para esquerda
index += y * CUBE_SIZE + (CUBE_SIZE - 1 - x);
} else {
// Linhas pares: esquerda para direita
index += y * CUBE_SIZE + x;
}
return index;
}
// Interpolação suave
float smoothstep(float x) {
x = constrain(x, 0.0, 1.0);
return x * x * (3.0 - 2.0 * x);
}
// Onda suave
float smoothWave(float x) {
return (sin(x) + 1.0) * 0.5;
}
// Espiral esférica áurea (Fibonacci Sphere)
void fibonacciSpherePoint(int i, int total, float& x, float& y, float& z) {
float goldenAngle = PI * (3.0 - sqrt(5.0)); // ~137.5 graus em radianos
float theta = goldenAngle * i;
float phi = acos(1.0 - 2.0 * (i + 0.5) / total);
x = cos(theta) * sin(phi);
y = sin(theta) * sin(phi);
z = cos(phi);
}
// Distância 3D
float dist3D(float x1, float y1, float z1, float x2, float y2, float z2) {
float dx = x2 - x1;
float dy = y2 - y1;
float dz = z2 - z1;
return sqrt(dx*dx + dy*dy + dz*dz);
}
void loop() {
uint32_t ms = millis();
// Múltiplos tempos para camadas
float t1 = ms * 0.0004;
float t2 = ms * 0.0008;
float t3 = ms * 0.0012;
// Centro do cubo
float centerX = (CUBE_SIZE - 1) / 2.0;
float centerY = (CUBE_SIZE - 1) / 2.0;
float centerZ = (CUBE_SIZE - 1) / 2.0;
float maxDist = sqrt(3.0 * centerX * centerX);
// Pontos da espiral de Fibonacci para animação
int numSpiralPoints = 21; // Número Fibonacci
for (uint8_t z = 0; z < CUBE_SIZE; z++) {
for (uint8_t y = 0; y < CUBE_SIZE; y++) {
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
// Coordenadas normalizadas [-1, 1]
float nx = (x - centerX) / centerX;
float ny = (y - centerY) / centerY;
float nz = (z - centerZ) / centerZ;
// Distância do centro (esférica)
float dist = sqrt(nx*nx + ny*ny + nz*nz);
// Coordenadas esféricas
float theta = atan2(ny, nx); // Ângulo no plano XY
float phi = acos(constrain(nz / (dist + 0.001), -1.0, 1.0)); // Ângulo vertical
// === CAMADA 1: Espiral Áurea Esférica ===
float spiralIntensity = 0;
for (int i = 0; i < numSpiralPoints; i++) {
float sx, sy, sz;
fibonacciSpherePoint(i, numSpiralPoints, sx, sy, sz);
// Rotacionar pontos da espiral
float rotAngle = t1 * 2.0;
float rx = sx * cos(rotAngle) - sy * sin(rotAngle);
float ry = sx * sin(rotAngle) + sy * cos(rotAngle);
float rz = sz;
// Escalar para o tamanho do cubo
float scale = 0.7 + smoothWave(t2 + i * 0.5) * 0.3;
float px = centerX + rx * centerX * scale;
float py = centerY + ry * centerY * scale;
float pz = centerZ + rz * centerZ * scale;
// Distância do pixel ao ponto da espiral
float d = dist3D(x, y, z, px, py, pz);
float pointGlow = exp(-d * d * 0.5);
spiralIntensity = max(spiralIntensity, pointGlow);
}
// === CAMADA 2: Ondas Esféricas Concêntricas ===
float sphericalWave = smoothWave(dist * 6.0 * PHI - t1 * 4.0);
sphericalWave = pow(sphericalWave, 1.5);
// === CAMADA 3: Rotação Toroidal ===
float torusR = 0.5; // Raio maior
float torusr = 0.25; // Raio menor
float torusDist = sqrt(pow(sqrt(nx*nx + ny*ny) - torusR, 2) + nz*nz);
float torusIntensity = exp(-pow((torusDist - torusr) * 8.0, 2.0));
// Rotacionar torus
float torusRotation = smoothWave(theta * 3.0 + t2 * 3.0);
torusIntensity *= torusRotation;
// === CAMADA 4: Helix Dupla (DNA-like) ===
float helixAngle1 = theta * 5.0 + nz * 8.0 - t2 * 4.0;
float helixAngle2 = theta * 5.0 + nz * 8.0 + PI - t2 * 4.0;
float helix1 = exp(-pow(dist - 0.6, 2.0) * 12.0) * smoothWave(helixAngle1);
float helix2 = exp(-pow(dist - 0.6, 2.0) * 12.0) * smoothWave(helixAngle2);
float helixIntensity = max(helix1, helix2);
// === CAMADA 5: Planos Rotativos ===
float planeAngle = t3;
float planeDist = abs(nx * cos(planeAngle) + ny * sin(planeAngle));
float planeIntensity = exp(-pow(planeDist * 4.0, 2.0));
planeIntensity *= smoothWave(nz * 5.0 - t1 * 2.0);
// === CAMADA 6: Pulsação Central ===
float pulse = smoothWave(t1 * 2.5);
float centralGlow = exp(-dist * dist * 3.0) * pulse * 0.4;
// Combinar todas as camadas
float intensity = 0;
intensity += spiralIntensity * 0.30;
intensity += sphericalWave * 0.20;
intensity += torusIntensity * 0.15;
intensity += helixIntensity * 0.15;
intensity += planeIntensity * 0.10;
intensity += centralGlow * 0.10;
intensity = constrain(intensity, 0.0, 1.0);
intensity = pow(intensity, 0.75); // Gamma correction
// Índice de cor 3D fluido
float hueBase = theta * 40.7436654315;
float huePhi = phi * 30.0;
float hueDist = dist * 100.0;
float hueTime = t2 * 120.0;
float hueNoise = sin(nx * 3.0 + t1) * sin(ny * 3.0 - t1) * sin(nz * 3.0 + t1) * 30.0;
float totalHue = hueBase + huePhi + hueDist + hueTime + hueNoise;
// Adicionar modulação áurea
totalHue += smoothWave(dist * PHI * 5.0 - t1 * 3.0) * 40.0;
// Converter para índice de 16 bits
uint16_t hueIndex = (uint16_t)(fmod(totalHue, 360.0) * 182.044);
// Brilho
uint8_t brightness = (uint8_t)(intensity * 255.0);
// Aplicar cor
leds[XYZ(x, y, z)] = ColorFromPaletteExtended(currentPalette, hueIndex, brightness, LINEARBLEND);
}
}
}
FastLED.show();
}