// Efeito Fibonacci Áurea Ultra Fluido - 16x16
// Movimento orgânico inspirado em fenômenos naturais
#include <FastLED.h>
#define WIDTH 16
#define HEIGHT 16
#define NUM_LEDS ((WIDTH) * (HEIGHT))
CRGB leds[NUM_LEDS + 1];
// 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); // Máximo de fluidez
}
uint16_t XY(uint8_t x, uint8_t y) {
if (x >= WIDTH) return NUM_LEDS;
if (y >= HEIGHT) return NUM_LEDS;
return y * WIDTH + x;
}
// Interpolação suave (smoothstep)
float smoothstep(float edge0, float edge1, float x) {
x = constrain((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return x * x * (3.0 - 2.0 * x);
}
// Função de onda suave
float smoothWave(float x) {
return (sin(x) + 1.0) * 0.5;
}
// Espiral logarítmica áurea
float goldenSpiral(float angle, float timeOffset) {
float normalizedAngle = fmod(angle + timeOffset, TWO_PI);
return exp(0.306349 * normalizedAngle); // ln(φ)/(π/2)
}
void loop() {
uint32_t ms = millis();
// Múltiplos tempos para criar camadas de movimento (parallax)
float t1 = ms * 0.0003; // Camada lenta
float t2 = ms * 0.0007; // Camada média
float t3 = ms * 0.0012; // Camada rápida
// Centro da matriz
float centerX = (WIDTH - 1) / 2.0;
float centerY = (HEIGHT - 1) / 2.0;
float maxDist = sqrt(centerX * centerX + centerY * centerY);
for (byte y = 0; y < HEIGHT; y++) {
for (byte x = 0; x < WIDTH; x++) {
// Coordenadas normalizadas [-1, 1]
float nx = (x - centerX) / centerX;
float ny = (y - centerY) / centerY;
// Distância e ângulo
float dist = sqrt(nx * nx + ny * ny);
float angle = atan2(ny, nx);
// === CAMADA 1: Espiral Áurea Principal ===
float spiral1 = goldenSpiral(angle * 3.0, t1 * 4.0);
spiral1 = fmod(spiral1, 2.0) / 2.0;
float spiralIntensity1 = exp(-pow((dist - spiral1) * 5.0, 2.0));
// === CAMADA 2: Espiral Secundária (contra-rotação) ===
float spiral2 = goldenSpiral(-angle * 2.0, -t2 * 3.0);
spiral2 = fmod(spiral2, 1.8) / 1.8;
float spiralIntensity2 = exp(-pow((dist - spiral2) * 4.0, 2.0));
// === CAMADA 3: Ondas Radiais ===
float radialWave = smoothWave(dist * 8.0 * PHI - t1 * 5.0);
radialWave = pow(radialWave, 1.5);
// === CAMADA 4: Padrão Angular Fibonacci (13 pétalas) ===
float petalAngle = angle * 13.0 + t2 * 4.0;
float petals = smoothWave(petalAngle) * (1.0 - dist * 0.3);
petals = pow(petals, 2.0);
// === CAMADA 5: Rotação de Cor Áurea ===
float colorAngle = angle * 8.0 + dist * 5.0;
float colorWave = smoothWave(colorAngle - t3 * 3.0);
// === CAMADA 6: Pulsação Central ===
float pulse = smoothWave(t1 * 2.0);
float centralGlow = exp(-dist * dist * 2.0) * pulse * 0.5;
// Combinar todas as camadas com pesos orgânicos
float intensity = 0;
intensity += spiralIntensity1 * 0.35;
intensity += spiralIntensity2 * 0.25;
intensity += radialWave * 0.15;
intensity += petals * 0.15;
intensity += centralGlow * 0.10;
intensity = constrain(intensity, 0.0, 1.0);
intensity = pow(intensity, 0.8); // Gamma correction para melhor visibilidade
// Índice de cor super fluido usando múltiplas fontes
float hueBase = angle * 40.7436654315; // Conversão linear ângulo->graus
float hueDist = dist * 80.0;
float hueTime = t2 * 150.0;
float hueSpiral = colorWave * 50.0;
// Combinar componentes de cor usando ângulo áureo
float totalHue = hueBase + hueDist + hueTime + hueSpiral;
totalHue += sin(dist * PHI * 4.0 - t1 * 2.0) * 20.0; // Modulação suave
// Converter para índice de 16 bits
uint16_t hueIndex = (uint16_t)(fmod(totalHue, 360.0) * 182.044);
// Brilho com curva suave
uint8_t brightness = (uint8_t)(intensity * 255.0);
// Aplicar cor com máxima suavidade
leds[XY(x, y)] = ColorFromPaletteExtended(currentPalette, hueIndex, brightness, LINEARBLEND);
}
}
// Blur sutil para suavidade extra (opcional - teste com/sem)
blur2d(leds, WIDTH, HEIGHT, 32);
FastLED.show();
}