//https://www.shadertoy.com/view/Wd3GWX

#define TIME_MULTIPLIER 1.0
#define TIME_DIVISOR 30.0

float createCircle(vec2 xy, vec2 center, float radius){
    vec2 dist = xy-center;   
    float p = 3./(iResolution.x);
    return 1.-smoothstep(radius-p, radius+p, dot(dist,dist));
}

float dVectorDegree(vec2 origin, vec2 u, vec2 v, float degree){
    float degreeUV = mod(angleBetweenVectors(u, v),360.0);
    degree = mod(degree, 360.);
    float d = (3./iResolution.y)*360.;
    return smoothstep(degreeUV-d, degreeUV+d, degree);
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    uv -=0.5;
	uv.x *= iResolution.x/iResolution.y;
    
    vec3 col = vec3(0);
    vec2 circle = vec2(0,0);
    float radius = 0.1;
    
    vec3 insideColor = 1. + 0.5 * sin(iTime+uv.xyx+vec3(0,2,4));
    insideColor *= createCircle(uv, circle, radius);
    
    float time = iTime*TIME_MULTIPLIER/TIME_DIVISOR;
    float inverseTime = mod(iTime*TIME_MULTIPLIER,TIME_DIVISOR/2.0)/TIME_DIVISOR;
    
    float degree = secondsToDegrees(time);
    float inverseDegree = secondsToDegrees(inverseTime);
    
    if(checkQuadrant(uv, 0) || checkQuadrant(uv,1) ){
        insideColor*= dVectorDegree(circle, vec2(0,1), uv, degree);
    }else if(checkQuadrant(uv, 2) && degree >=180.){
    	insideColor*= dVectorDegree(circle, vec2(0,-1), uv, inverseDegree);
    }else if (checkQuadrant(uv, 3) && degree >=270.){
    	insideColor*= dVectorDegree(circle, vec2(0,-1), uv, inverseDegree);
    }else insideColor = vec3(0);
    
    col = insideColor;
    fragColor = vec4(col,1.0);
}