uniform float ptimer;

const int n = 48;

void main()
{
	float x0 = (gl_TexCoord[0].x - 0.5) * 2.0;
	float y0 = (gl_TexCoord[0].y - 0.5) * 2.0;
	vec2 pix = vec2(x0, y0);

	float r = distance(vec2(x0,y0),vec2(0,0));
	float ri = sin(r * 0.25 + ptimer) * 1.5 + sin(r * 0.75 + 1.5 * ptimer) * 0.5;

	float min = 256.0;
	for (int i=0; i<n; i++)
	{
		float ii = float(i);

		float px = sin(ii*ii + ptimer + ri);
		float py = sin(ii*ii*ii + ptimer + ri);
		vec2 p = vec2(px, py);

		float dist = distance(pix, p);
		if (min > dist)
			min = dist;
	}

	float c = 2.0 * min;
	gl_FragColor = vec4(c, c, c, 1.0);
}
