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

#define pi 3.14159265359
#define tpi 6.28318530718
#define color(offset) abs(sin(offset + vec3(3.0, 7.0, 11.0) * pi/6.0))

float sdfTriangle(vec2 plane, vec2 pos, float radius, float thickness, float rotation)
{
    float angle = mod(atan(plane.x-pos.x,plane.y-pos.y)/(2.0*pi), 1.0);
    float adAngle = 2.0*pi*mod(angle + rotation, 1.0/3.0);
    
    float TxDeflect = sin(adAngle) - 1.0/( 1.0/tan(adAngle) + sqrt(3.0));
    float TyDeflect = cos(adAngle) - 1.0/( sqrt(3.0)*tan(adAngle) + 1.0);
    float tDeflect = radius * sqrt( pow(TxDeflect, 2.0) + pow(TyDeflect, 2.0) );
    
    float triangle = thickness/abs(length(plane-pos)-radius + tDeflect);
    return triangle;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (fragCoord-0.5*iResolution.xy)/iResolution.y;
    vec3 col = vec3(0.0);
    
    float angle = mod(atan(uv.x,uv.y)/(2.0*pi), 1.0);
    
    for(float i = 0.0; i <= 40.0; i+=2.0)
    {
        float brightness = 0.05;
        col += brightness*color(iTime  + pi*angle) * sdfTriangle(vec2(uv.x, uv.y), vec2(0.0, 0.0), 0.05*i, 0.01, 0.01*iTime*i);
        col += brightness*color(iTime  + pi*angle) * sdfTriangle(vec2(-uv.x, uv.y), vec2(0.0, 0.0), 0.05*i, 0.01, 0.01*iTime*i);
        col += brightness*color(iTime  + pi*angle) * sdfTriangle(vec2(-uv.x, -uv.y), vec2(0.0, 0.0), 0.05*i, 0.01, 0.01*iTime*i);
        col += brightness*color(iTime  + pi*angle) * sdfTriangle(vec2(-uv.x, -uv.y), vec2(0.0, 0.0), 0.05*i, 0.01, 0.01*iTime*i);
    }

    fragColor = vec4(col,1.0);
}