#version 330 core
out vec4 FragColor;
in vec2 vUV;
uniform vec3 iResolution;
uniform float iTime;
uniform vec2 iMouse;
uniform float uAlpha;

// inspired from https://www.shadertoy.com/view/XdfSWN

// simplier version here: https://www.shadertoy.com/view/XsVSWK

#define N 100.

void mainImage( out vec4 o, vec2 u ) {
    
	float t = iTime/2.,           // rotation at scaling
		 st = 2.*exp(-6.*(1.-cos(.1*t))), 
         c = cos(t),s = sin(t); 
    mat2 M = mat2(c,-s,s,c);
    
	vec2 R = iResolution.xy,            // coordinates transform
        z0 = st * M * (u/R.y - vec2(1.1,.5)) -vec2(.4615,-.622), 
         z = z0, 
		m = length(iMouse.xy)==0. ? z-z : st*2.*(iMouse.xy/R.y-vec2(1.1,.5));

    o -= o;
	for (float i=0.; i<N; i++) {
		if (dot(z,z)>4.) { o = vec4(1.-i/N); return;} // z diverged
		z -= m;
		z = z0+m + mat2(z,-z.y,z.x)*z; 
	}
}

void main() {
    mainImage(FragColor, gl_FragCoord.xy);
    FragColor.a *= uAlpha;
}
