// zoom-in coordinates
#define CX -.743641
#define CY  .131828

void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
    vec2 p = (-iResolution.xy + 2.0*(fragCoord.xy))/iResolution.y;
    
    float zoom = cos(iTime*.4)*.5+.5; // horizontal diameter
    zoom = pow(zoom*.75 + .27, 8.);
        
    vec3 color;
    vec2 c = p * zoom + vec2(CX, CY);
    vec2 z = vec2(0.);
    
    // don't render inside M1 and M2 bulbs - https://iquilezles.org/articles/mset1bulb
    float c2 = dot(c, c); 
    if(256.*c2*c2 - 96.*c2 + 32.*c.x < 3. || 16.*(c2+2.*c.x+1.) < 1.) {
        fragColor = vec4(color, 1.0); return;    
    }
    
    for (float iter = 0.; iter < 400.; iter++) {
        z = vec2(z.x*z.x - z.y*z.y, 2.*z.x*z.y) + c; // z(n+1) = z^2 + c
        
        if (dot(z,z) > 40.) { // pixel is outside the set
            float smooth_iter = iter + 1. - log(log(dot(z,z)))/log(2.); // smooth iteration count
            color = cos(vec3(1.1,1.2,1.3) * sqrt(smooth_iter*2.)); // colorize
            break;
        }
    }
    
    fragColor = vec4(color, 1.0);
}
