// --- key toggles -----------------------------------------------------
// FYI: LEFT:37  UP:38  RIGHT:39  DOWN:40   PAGEUP:33  PAGEDOWN:34  END : 35  HOME: 36
// Modifiers: SHIFT: 16 CTRL: 17 ALT: 18  
// Advice:  Mode: keyToggle(key)  Action: keydown(key)+keyclick(modifier)
#define keyToggle(ascii)  ( texelFetch(iChannel3,ivec2(ascii,2),0).x > 0.)
#define keyDown(ascii)    ( texelFetch(iChannel3,ivec2(ascii,1),0).x > 0.)
#define keyClick(ascii)   ( texelFetch(iChannel3,ivec2(ascii,0),0).x > 0.)
 
#define lim .3
 
float flower(vec2 uv ,float petals, float speed , float size ) {
    vec2 st= vec2(atan(uv.x, uv.y), length(uv));
    uv= vec2(st.x/6.2831 +.5 + iTime * speed, st.y);
    float x=uv.x * petals;
    float m= min(fract(x), fract(1.-x));
                return smoothstep(0., .15,m*size + .2 - uv.y);                 
}
 
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = (fragCoord.xy-.5*iResolution.xy) /iResolution.y;
 
    float cr=flower(uv, 8., .05, .50);
    float cg=flower(uv, 7., .1, .60);
    float cb=flower(uv, 6., .15, .8);
 
    if (keyClick(49)) {
        if (cr>lim) { cg=0.; cb=0.; }
        else {
            if(cg>lim) cb=0.; 
        }
                    fragColor = vec4(cr,cg,cb,0.);
    }
    else if (keyClick(50)) {
        if (cg>lim) { cr=0.; cb=0.; }
        else {
            if(cr>lim) cb=0.; 
        }
                    fragColor = vec4(cr,cg,cb,0.);
    }
    else if (keyClick(51)) {
        if (cb>lim) { cr=0.; cg=0.; }
        else {
            if(cg>lim) cr=0.; 
        }
                    fragColor = vec4(cr,cg,cb,0.);
    }
    else {
                    fragColor = vec4(cr,cg,cb,0.);
    }
    
}
