IoT Shader Simulator
Browser:
0
FPS
ESP32:
~47
FPS
cosmos
fire
+
AI
Export .js
Export .h
// Cosmos — fractal palette shader (ShaderToy port) // Resolution for normalizing pixel coordinates const res = W; // Map pixel to [-1, 1] UV space (centered) let uvx = (px * 2.0 - res) / res; let uvy = (py * 2.0 - res) / res; // Save original UV for palette and distance falloff const uv0x = uvx, uv0y = uvy; // Accumulated color channels let fr = 0, fg = 0, fb = 0; // Distance from center (used for palette + glow falloff) const len_uv0 = length(uv0x, uv0y); // Exponential falloff — dims pixels far from center const e_neg = exp(-len_uv0); // 4 fractal iterations, each zooming into the pattern for (let i = 0; i < 4; i++) { // Repeat UV space: zoom 1.5x and wrap to [-0.5, 0.5] uvx = fract(uvx * 1.5 + 0.5) - 0.5; uvy = fract(uvy * 1.5 + 0.5) - 0.5; // Distance from cell center in this iteration const len_uv = length(uvx, uvy); // Combine cell distance with center falloff let d = len_uv * e_neg; // Oscillating wave pattern driven by time d = sin(d * 8.0 + iTime) / 8.0; // Absolute value creates mirrored ridges d = abs(d); // Invert and sharpen — small d = bright glow d = pow(0.01 / (d + 0.0001), 1.2); // Cosine palette: shifts hue based on distance + iteration + time const t = len_uv0 + i * 0.4 + iTime * 0.4; const cr = 0.5 + 0.5 * cos(6.28318 * (t + 0.263)); // red channel offset const cg = 0.5 + 0.5 * cos(6.28318 * (t + 0.416)); // green channel offset const cb = 0.5 + 0.5 * cos(6.28318 * (t + 0.557)); // blue channel offset // Add this iteration's colored glow to the total fr += cr * d; fg += cg * d; fb += cb * d; } // Clamp to [0,1] and scale to 0-255 RGB return [clamp(fr, 0, 1) * 255, clamp(fg, 0, 1) * 255, clamp(fb, 0, 1) * 255];