// https://iquilezles.org/articles/palettes/
// Also http://dev.thi.ng/gradients/
vec3 palette(in float t)
{
    vec3 a=vec3(0.000,0.500,0.500);
    vec3 b=vec3(0.000 ,0.500 ,0.500);
    vec3 c=vec3(0.000, 0.500 ,0.333);
    vec3 d=vec3(0.00, 0.500 ,0.667);
    return a+b*cos(6.28318*(c*t+d));
}

vec3 mandelbroot(vec2 point){
    vec2 c = vec2(0.); 
    float o1=2000.;
    float o2=2000.;
    
    for(int i=0;i<64;i++){
        float sr=c.x*c.x-c.y*c.y;
        float sc=2.*c.y*c.x;
        
        c.x=sr+point.x;
        c.y=sc+point.y;
        float l = length(vec2(c.x+2.,0.));
        o1=min(o1, l);
        float l2 = length(vec2(c.x,c.y) - vec2(cos(iTime), sin(iTime)));
        o2=min(o2, l2);
    }
    
    vec3 col = (palette(o2) + palette(o1)) / 2.;
    return .3 / col;
}


void mainImage(out vec4 fragColor, vec2 fragCoord){
    vec2 st=(2.*fragCoord.xy-iResolution.xy)/iResolution.y;
    vec2 uv=(st-vec2(0.5,0)) * 1.2;
    
    vec3 color=mandelbroot(uv);
    
    fragColor=vec4(color,1.);
}
