float pi = 3.14159;
float theta = 0.5773503;

mat2 rot(float a)
{
    return mat2(cos(a),sin(a),-sin(a),cos(a));
}

mat2 shear(vec2 v)
{
  return mat2(1,v.x,v.y,1);
}




//used this years ago. dunno for what anymore.. something something unity.
//yes it is throw stuff at spiral time. why wo'T you work?
vec2 hexagon(in vec2 p)
	{
	vec2 q = vec2( p.x*2.0*theta, p.y + p.x*theta );
	vec2 pi = floor(q);
    vec2 pf = fract(q);
	float v = mod(pi.x + pi.y, 3.0);
	float ca = step(1.0,v), cb = step(2.0,v);
	vec2  ma = step(pf.xy,pf.yx);

	return vec2( pi + ca - cb*ma);
	}


vec2 expc(vec2 v){
   float x = exp(0.5)*sin(v.y);
   float y = exp(0.5)*cos(v.y);
   return vec2(x,y);
}


//Taken from https://www.shadertoy.com/view/WtSSDd
//Thanks to kb again



// complex logarithm
vec2 logc(vec2 v)
{
    return vec2(log(length(v)),atan(v.y,v.x));
}
// map from logarithmic spiral to time coordinates
vec2 spiral(vec2 uv, float spd, int amnt)
{
    float ts = iTime*spd;
    uv *= rot(sin(ts)*10.); // rotate

    uv = logc(uv.xy); // map from complex exp

    // scale
    vec2 uv2 = uv*vec2(0.1,1./(2.*pi));


    float st = mod(ts,float(amnt));

    // shear (y factor needs to be integer to avoid seams)
    // uncomment to see why :)
    //uv.x = float(st)*uv2.x + 9.*uv2.y;
    //uv.y = float(st)*uv2.y - 9.*uv2.x;

    uv.x = 4.*uv2.x + 9.*uv2.y;
    uv.y = 4.*uv2.y - 9.*uv2.x;
    // tile and shift
    return mod(uv,1.)-0.75;
}




void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = fragCoord/iResolution.xy;
    vec2 uvorig = uv;
    uv.xy -= .5; // center around 0
    uv.x /= iResolution.y/iResolution.x; // apply aspect


    uv.x*= 1.;
    uv.y *= 1.;
    uv= spiral(uv.xy, 0.5, 6);
    uv *= rot(0.2);

    //uv *= hexagon(uv*5.0);
    uv = abs(uv);
      vec2 hex = hexagon(uvorig*20.0);

// Time varying pixel color
    vec3 col = cos(5.*vec3(uv,0.)+iTime);
     col *= hex.x;
    // Output to screen
    fragColor = vec4(col,1.0);
}