mandelbrot
🧩 Syntax:
precision highp float;
uniform float time;
varying vec2 vUv;
float mandelbrot(vec2 c) {
vec2 z = c;
float iterations = 100.0;
for (float i = 0.0; i < iterations; i++) {
z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
if (length(z) > 2.0) {
return i / iterations;
}
}
return 0.0;
}
void main() {
vec2 uv = vUv * vec2(3.0, 2.0) - vec2(2.0, 1.0); // Adjust the Mandelbrot set position and scale
float mandel = mandelbrot(uv);
// Color based on Mandelbrot iteration
vec3 color = vec3(0.0);
if (mandel > 0.0) {
color = vec3(1.0 - smoothstep(0.0, 1.0, mandel));
}
gl_FragColor = vec4(color, 1.0);
}