vec3 hsv2rgb(vec3 c)
{
    vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}


void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float PI = 3.14159263;
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;
    float freq;
    float radius;
    float t;
    float rot;
    int numEl;
    float scale = 1.; //how bright the image is. set very high for pure B/W, set lower for grayscale
    int choice = 0; //choice between settings. mainly for quickly changing
    //between constant and varying frequencies

    freq = 120.; //busyness of screen
    rot = 0.5; //how fast the screen rotates
    t = iTime*0.01*60.; //a timing constant
    numEl = 2; //number of radiators on ring
    radius = .2*cos(t)+0.4; //radius of circle of points

    float col = 0.;
    uv = fragCoord/iResolution.xy; //reset coordinate plane
    uv.x *= iResolution.x/iResolution.y; //scale coordinates
    uv.x -= 0.5*iResolution.x/iResolution.y +0.2*cos(0.7*t); //move origin
    uv.y-=0.3*cos(t)+0.5; //move origin
    uv.x-=radius*cos(2.*3.14159*cos(t*0.2)-rot*t); //move to each point on ring
    uv.y-=radius*sin(2.*3.14159*sin(t*0.21)-rot*t);

    col+=(scale/float(numEl))*cos(freq*length(uv)-t); //sum up the field magnitude at each point due to each radiator
    //0.77 is a scaling factor. Set higher for wider color range.

    uv = fragCoord/iResolution.xy; //reset coordinate plane
    uv.x *= iResolution.x/iResolution.y; //scale coordinates
    uv.x -= 0.5*iResolution.x/iResolution.y +0.2*cos(0.7*t); //move origin
    uv.y-=0.3*cos(t)+0.5; //move origin
    uv.x-=radius*cos(2.*3.14159*sin(t*0.15-0.1)-rot*t); //move to each point on ring
    uv.y-=radius*sin(2.*3.14159*cos(t*0.1-0.4)-rot*t);

    col+=(scale/float(numEl))*cos(freq*length(uv)-t); //sum up the field magnitude at each point due to each radiator
    //0.77 is a scaling factor. Set higher for wider color range.

    //col = normalize(col);
    vec3 c = vec3(col+.1, 0.7, col+0.9); //mess with this to get different color mappings


    //vec3 c = vec3(col*sin(t), col*cos(t), col*cos(t*0.5+0.5));//all these constants are to get a nice color
    //colors are hard, so I put oscillations in so eventually the colors will look good. Thats when you screenshot or record
    c = hsv2rgb(c); //I find HSV to be easier to work in, but there are cool color schemes in RGB too.
    fragColor = vec4(vec3(c), 1.0);
}
