
#define S(a,b,t)  mix(a, b, sin(t) * .5 + .5)
#define C(a,b,t)  mix(a, b, cos(t) * .5 + .5)

float sFract(float x){
    
    // Smoothing factor that takes resolution into account.
    // Constants, like 12, etc, can work too.
    float sf = .02*iResolution.y; // Tailor to suit needs.
    x = fract(x);
    return min(x, x*(1. - x)*sf);
    
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float t = iTime * .2;
    
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = (fragCoord-.5*iResolution.xy)/iResolution.y;

    // polar coords
    float a = atan(uv.x, uv.y) / 6.28 + .5;
    float l = length(uv);
    
    // petals
    float p = a*7.;
    p = min(sFract(p), sFract(-p))
        * S(4.,10.,t*S(1., 2., t*.0001));
    
    // rings
	float r = l*S(.2,1.,t)
        + sin(l*S(7.,14.,t) - t*3.);
    
    // mask
    float m = sqrt(l);
    
    // combined
    float c = sFract(p + r) * m + m;
//	  float w = 1.-fwidth(p+r);
//    float c = (p+r)*m;
//    c = ( 1. + (c < w ? c/w : 1.-(c-w)/(1.-w)) ) ;
	 
    // color
    float R = .5;
    float G = S(0., l, t*1.5+1.1);
    float B = S(l, 1., t);
    vec3 col = c*vec3(R,G,B);

    // Output to screen
    fragColor = vec4(col,1);
}
