uniform vec2 iResolution;
uniform float iTime;

uniform sampler2D gm_BaseTexture;

uniform bool gm_PS_FogEnabled;
uniform vec4 gm_FogColour;
uniform bool gm_AlphaTestEnabled;
uniform float gm_AlphaRefValue;

void DoAlphaTest(vec4 SrcColour)
{
	if (gm_AlphaTestEnabled)
	{
		if (SrcColour.a <= gm_AlphaRefValue)
		{
			discard;
		}
	}
}

void DoFog(inout vec4 SrcColour, float fogval)
{
	if (gm_PS_FogEnabled)
	{
		SrcColour = mix(SrcColour, gm_FogColour, clamp(fogval, 0.0, 1.0)); 
	}
}

#define _YY_GLSL_ 1
varying vec2 fragCoord; 
vec2 uv;
vec3 rgb;

const float PI = 3.1415926535897;

void circle( vec2 offset, float radius, vec3 color )
{
    vec3 intensity = vec3(radius/length(uv+offset));
    rgb += intensity * color;
}

void circle( vec2 offset )
{
    circle(offset, 1., vec3(1.,1.,1.));
}

float normalcos( float a )
{
	return (cos(a)+1.)/2.;
}

float normalsin( float a )
{
	return (sin(a)+1.)/2.;
}

void main()
{
    vec2 fragCoord = openfl_TextureCoordv * iResolution;

	uv = fragCoord.xy / iResolution.xy;
    
    uv = uv * 2.0 - 1.0;
    uv.x *= iResolution.x / iResolution.y;
    
    vec2 mp;
    
    mp = vec2(0.5 * 2.);
    mp.x *= iResolution.x / iResolution.y;
    
    rgb = vec3(0.,0.,0.);

    float rings = 6.;
    
    for ( float h = 0.; h < 6.; h++ )
    {
        float balls = 10.;
    	float rad = (0.4*h+0.1)*sin((iTime*h*h*h)/1000.)+0.1;
    	float slice = PI*2. / balls;
    	for ( float i = 0.; i < 10.; i++ )
        {
            vec2 p = vec2(slice*i+iTime+1./rad);
            p+=mp+vec2((h/rings)*PI*2.+iTime/8.,0.);
            p.x=sin(p.x);
            p.y=cos(p.y);
            
            p*=rad+0.01;

            float color=(i/balls)*PI*2.;
            
            circle(vec2(p), 0.02/(rad*rad+1.), vec3(normalcos(color+iTime),normalcos(color+iTime+(2.*PI)/3.),normalcos(color+iTime+(4.*PI)/3.)));
        }
    }
    
	gl_FragColor = vec4(rgb,1.);
}