
// based on...
// https://www.shadertoy.com/view/lssfW2

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;
    vec2 p=(2.0*fragCoord.xy-iResolution.xy)/iResolution.y;
    // Time varying pixel color
    //vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
    
    vec2 curve_p = vec2(0,200);
    float d = 10000.0 + 4200.*sin(iTime)+4200.*cos(iTime);
    float di = 2.;// +3.2*sin(iTime * .1);
    for(int i = 0;i<300;i++)
    {
        di = float(i)*.3;
        curve_p.x = .5-.3*sin(.3*iTime)-.05*float(di)*cos(float(di)+.4*iTime); // +.01*float(di)*sin(4.0*di+.2*iTime) + .03*sin(iTime*.1)*float(di)*sin(7.0*di+.4*iTime);
        curve_p.y = .5-.3*cos(.3*iTime)-.05*float(di)*sin(float(di)+.2*iTime); // +.01*float(di)*cos(4.0*di+.2*iTime) + .03*sin(iTime*.1)*float(di)*cos(7.0*di+.4*iTime);
        d = sin(min(d*1.0, 1.*sin(length(p-curve_p))));
        //d = length(p-curve_p)/(di+1.0);
  
    }
    float r =.05*d + .05*(.05 - .015*pow(dot(sin(p*p + d*d), log(20.0+2.*curve_p -d)),2.0));
    float g = .0008 + .005*cos(.001*d*d*d+3.1*length(p)); //+.03*dot(p,curve_p + .0005*vec2(iTime, iTime));
    float b=2.5*abs(.5+.3*cos(iTime*.8 - 2.5*pow(d,2.0))); // +.01*(dot(p,curve_p - .005*vec2(iTime-200.05, iTime-200.05)+10.0));
    if (d < 2.2)
    {
        b = .0 +.04*(.5+ .5*sin(iTime*.1 + 1.28*dot(p,curve_p)));
    }
    float checkers = mod(float(uv.x*uv.x +uv.y*uv.y)+r*r*1200.+b*20., .25);
    float checkers_02 =mod(float( -.01*curve_p.x*curve_p.y)+g*g*1000.,.25);
    if (checkers + checkers_02 > .25)
    {
        r = 0.06*r;
        g = 1.2*g;
        b = 1.2*b;
    }
    vec3 col = vec3(r, g, b);
    float dn = col.x + col.y + col.z;
    col /= dn;
    // Output to screen
    fragColor = vec4(col,1.0);
}
