## Exotic functions

In my generative 2d art such as Aleph Null and dbCinema, a virtual ‘brush’ moves around the screen ‘painting’. So I have need of functions that aren’t particularly predictable but buzz around the screen–and stay on screen. Ideally, they’d look like a human scrawl. Like the graphics in this article.

What I’d like to do in this article is illustrate how to use and/or create some exotic functions in your own programming work that could help you achieve a look that isn’t spirographic, ie, too orderly to be of much interest.

There’s a math theorem that says that any curve whatsoever–hand drawn or whatever–can be represented as accurately as you please with trigonometric functions. Trig functions, in the right hands, can be very expressive. Not spirographic or predictably cyclic. They can be sinuous and right there with us on the mind’s tangents. Anyone who thinks that any curve expressed by trig functions lacks the hand’s humanity just has no idea what is possible with trig functions, has no sense of the theory at all, or just hasn’t seen any good applications. Or didn’t know it when they saw it.

It’s important to note that both sin(t) and cos(t) have a maximum value of 1 and a minimum value of -1. That makes them easy to scale to take up as much or as little of the screen as we like, as we’ll see.

The simplest function of the sort I want to talk about is just a circle. This describes a circle of radius 1. The circle is centered at the origin:

x=cos(t)

y=sin(t)

t is short for ‘theta’. If you want to trace the circle just once, then you let t vary from 0 to 2*pi. The smaller the increment of t, the closer the points of the circle will be to one another. If you want to trace the circle multiple times, you let t vary through more than 2*pi values. I normally just keep incrementing t until it reaches some very very high value and then knock t back to 0.

If the increment has a negative value, the brush will move in the opposite direction.

Now, if we want the radius of the circle to be of size r (constant), this will do the job:

x=r*cos(t)

y=r*sin(t)

We can see that this is so cuz we know that sin(t) and cos(t) have a min of -1 and a max of 1. So r*cos(t) is going to have a min of -r and a max of r. So too with r*sin(t). Consequently, the above describes a circle of radius r centered at the origin.

If we want an ellipse rather than a circle, where the x radius is xRadius (constant) and the y radius is yRadius (constant), this will do the job:

x=xRadius*cos(t)

y=yRadius*sin(t)

If we want to make the circle be centered at the center of the screen, we have to translate the x coordinate by half the width (w) of the screen and the y coordinate by half the height (h) of the screen.

x=xRadius*cos(t) + w/2

y=yRadius*sin(t) + h/2

So the above describes an ellipse centered at (w/2,h/2). More generally, if we want the ellipse centered at (a,b) then this will do the job:

x=xRadius*cos(t) + a

y=yRadius*sin(t) + b

Now, it looks like we’ve just learned how to work with cirles and ellipses, but we’ve also learned how to scale trig functions and how to translate them. And that will be useful in what follows.

One of my faves of the exotic functions (I call it the Lily) is this:

x=xRadius*cos(c1*t)*cos(c2*t)

y=yRadius*cos(c3*t)*cos(c4*t)

The above is centered at (0,0). So we need to translate it to be centered in the middle of the screen:

x=xRadius*cos(c1*t)*cos(c2*t) + w/2

y=yRadius*cos(c3*t)*cos(c4*t) + h/2

Now, the above has a max x value of xRadius + w/2 (when cos(c1*t)*cos(c2*t)=1) and a min x value of -xRadius + w/2 (when cos(c1*t)*cos(c2*t)=-1). Why? Well, cos(t)*cos(v) has a max of 1 and a min of -1. Just like cos(t).And it has a max y value of yRadius + h/2 and a min y value of -yRadius + h/2.

It’s easy to manufacture your very own custom exotic functions. The above Lily function multiplies two trig functions together. The x value multiples cos*cos and so does the y value. But you can multiply as many cos or sin functions together as you like. The product will still have a min of xRadius or yRadius.

So, for instance,

x=xRadius*cos(c1*t)*sin(c2*t) + w/2

y=yRadius*cos(c3*t)*cos(c4*t) + h/2

or

x=xRadius*sin(c1*t)*sin(c2*t) + w/2

y=yRadius*cos(c3*t)*sin(c4*t) + h/2

or

x=xRadius*cos(c1*t)*cos(c2*t)*sin(c3*t) + w/2

y=yRadius*cos(c4*t)*cos(c5*t) + h/2

are all similar sorts of exotic functions.

Let me know if you’d like more exotic functions.