Defining shapes in terms of theta.

Polar Coordinates, composed of a magnitude (length) and phase (angle), can be constructed from Cartesian $(x,y)$ coordinates:

		float r = length(st);
		float theta = atan(st.y, st.x);
		

We can defining a shape using polar coordinates, by specifying a value for $r$ in terms of $\theta$.

	float f = pow(pow(cos(theta),2) + pow(sin(theta),2),1./2.);
	float v = step(f, r);
	vec3 color = vec3(v);
	

The above code defines a threshold value $f$ in terms of $\theta$, and sets all pixels whose length are below this threshold to black, and all that are above to white. We could try to use a more complicated polar form:

which we could code in this way:

float f = pow(pow(cos(theta*3.),4.0) + pow(sin(theta*8.),3.),1./10.)
float v = step(f,r);

(the 1./10. says we want the tenth rooth!).

This makes what starts to look like an “organic” shape. In fact, there is a generalization of these kinds of polar equations called the superformula. You can read about it here. The equation is as follows:

And an example of it in action in the fragment shader can be found here.