0.00
60.0 fps

Julia Set

Animation of Julia set ,written by gpt-4o

Log in to post a comment.

#version 300 es
#define pi 3.1415926
precision highp float;

uniform float iTime;
uniform vec2  iResolution;

out vec4 fragColor;

// Complex power of 2 for z = z^2 + c
vec2 complexPow2(vec2 v) {
    return vec2(v.x * v.x - v.y * v.y, 2.0 * v.x * v.y);
}

// Calculate the number of iterations before escaping
float juliaIterations(vec2 c, vec2 z) {
    int maxIterations = 256;
    int i = 0;

    while (length(z) < 4.0 && i < maxIterations) {
        z = complexPow2(z) + c;
        i++;
    }

    // Smooth coloring
    return float(i) + 1.0 - log(log(length(z))) / log(2.0);
}

// Generate a color based on iteration count
vec3 colorMap(float iteration) {
    if (iteration < 256.0) {
        return vec3(0.5 + 0.5 * cos(iteration / 12.0), 
                    0.5 + 0.5 * sin(iteration / 18.0), 
                    0.5 + 0.5 * sin(iteration / 24.0));
    }
    return vec3(0.0);
}

void main() {
    // Normalize coordinates to [-aspect, -1] to [aspect, 1]
    vec2 uv = (2.0 * gl_FragCoord.xy - iResolution) / iResolution.y;

    // Julia set parameters
    vec2 c = vec2(0.355 + 0.3 * sin(iTime * 0.3), 0.355 + 0.3 * cos(iTime * 0.4)); // Animate 'c'
    vec2 z = uv;

    // Calculate iterations
    float iteration = juliaIterations(c, z);

    // Compute color
    vec3 color = colorMap(iteration);

    // Output final color
    fragColor = vec4(color, 1.0);
}