#version 460 core
#include <flutter/runtime_effect.glsl>

uniform vec2 uSize;
uniform float iTime;
vec2 iResolution;
out vec4 fragColor;

#define PI 3.1415926535897932384626433832795
#define TWO_PI 6.28318530718

#define SCALE_FACTOR 8
#define TIME_SCALE 0.005

mat2 rotate2d(float _angle){
    return mat2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle));
}

void main(void) {

    iResolution = uSize;
    vec2 fragCoord = gl_FragCoord.xy; // Get the fragment coordinates
    vec2 center = 2.0 * vec2(fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
    
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;
    
    uv = uv * 2.0 - vec2(1.0);
    
    uv.y *= iResolution.y/iResolution.x;
    vec2 pos = vec2(0.) - uv;
    //pos += vec2(cos(iTime) - 0.04,sin(iTime)-0.04);
    mat2 rotation = rotate2d(PI/2. *  float(iTime/2));
    pos = rotation * pos;
    
    float len = length(pos);
    float angle = atan(pos.x,pos.y);
    
    float r = TWO_PI/float(3);

    float d = cos(floor(.5+angle/r)*r-angle)*length(pos);

    
    // Time varying pixel color
    vec3 col = vec3(0.0);
    col.g += (1.0 - step(0.2,d));
    // Output to screen
    fragColor = vec4(col,1.0);

    // Triangle logic (adjust for size and position)
    // if (center.y > -0.1 && // Smaller bound on the bottom
    // center.x > -sqrt(1.0) * center.y - 0.001  && // Smaller bound on the left
    // center.x < sqrt(1.0) * center.y + 0.1) { // Smaller bound on the right
    //         fragColor = vec4(1.0, 0.5, 0.2, 1.0);
    //         }
}
