float radial(vec2 pos, float radius)
{
    float result = length(pos)-radius;
    result = fract(result*1.0);
    float result2 = 1.0 - result;
    float fresult = result * result2;
    fresult = pow((fresult*5.5),10.0);
    fresult = clamp(0.0,1.0,fresult);
    return fresult;
}

const float PI = 3.14;

mat2 rotationMatrix(float angle)
{
	angle *= PI / 180.0;
    float s=sin(angle), c=cos(angle);
    return mat2( c, s, -s, c );
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
	vec2 uv = (fragCoord.xy / iResolution.xy) - .5;
	float t = iTime * .1 + ((.25 + .05 * sin(iTime * .1))/(length(uv.xy) + 1.07)) * 2.2;

	float si = sin(t);
	float co = cos(t);
	mat2 ma = mat2(co, si, -si, co);
uv *= rotationMatrix( 10.0 * -iTime );
	float v1, v2, v3;
	v1 = v2 = v3 = 0.0;


    vec2 c_uv = uv;
    vec2 o_uv = uv * 0.80;
    float gradient = radial(c_uv*rotationMatrix( 1.0 * iTime ), iTime*1.5);
    vec2 fuv = mix(uv,o_uv,gradient);
    vec3 col = texture(iChannel0,fuv).xyz;

	float s = 0.0;
	for (int i = 0; i < 90; i++)
	{
		vec3 p = s * vec3(uv,.1);
		p.xy *= ma;
        vec2 trs = vec2(cos(iTime*0.1),sin(iTime*0.3));
 p.xy+=trs;
		p += vec3(0.22, .03, s - 2.5 - sin(iTime * .13) * .1);
		for (int i = 0; i < 8; i++)	p = abs(p) / dot(p,p) - 0.659;
		v1 += dot(p,p) * .0015 * (0.8 + sin(length(uv.xy * 13.0) + .5  - iTime * .2));
		v2 += dot(p,p) * .0013 * (1.5 + sin(length(uv.xy * 14.5) + 1.2 - iTime * .3));
		v3 += length(p.xy*10.) * .0003;
		s  += .035;

	}

	float len = length(uv*rotationMatrix( 1.0 * -iTime ));

	v1 *= smoothstep(.7, .0, len);
    v1+=radial(col.xy*cos(iTime),2.2);
	v2 *= smoothstep(.5, .0, len);
	v3 *= smoothstep(.9, .0, len);

col+= vec3( v3 * (1.5 + sin(iTime * .2) * .4),
					(v1 + v3) * .3,
					 v2) + smoothstep(0.2, .0, len) * .85 + smoothstep(.0, .6, v3) * .3;

	fragColor=vec4(min(pow(abs(col), vec3(1.2)), 1.0), 1.0);
}
