Psychedelic Animations using Trigonometry

We will in this post showcase a method for generating psychedelic animations using the basic trigonometry functions sin(x), cos(x) and tan(x).

By animation, we mean a smoothly blending series of images of a given size. Suppose we just want to create a single image, we could define a function of two dependant variables f(x, y), where x and are the coordinates of a given point on the image. This means that the function depends on the x and coordinates, giving a smooth variation across the image.

Here is the image representing f(x, y) = x + y:


The brightness of a pixel is 256 – f(x) mod 256

This is nice. It’s a smooth image, however, it’s not very “psychedelic”. To accomplish this, we construct not one, but three functions R(x, y), G(x, y) and B(x, y) – one for each color channel. This produces the following image instead:


R(x, y) = sin(x+y)   G(x, y) = cos(x+y)  B(x, y) = sin(x) + cos(y)

This is perfect! This is trippy enough for our purposes, however, it’s not very “animated”. This is a single image, so it doesn’t really count as an animation. To make this an animation, we introduce another independant variable t (for time), so we get three functions R, G, B, dependant on three variables x, y, t. Introducing a time variable, produces animations like the follow:


Fewer colors in this than the actual version, due to .GIF file format

This is perfect! We can now construct animated psychedelic animations using math!

Here’s a link to a YouTube channel I made, which showcases a bunch of these:

Future ideas: Create the same program, but using HSB instead of RGB. My hypothesis is that this will create better, more trippy images.

Comment on this article

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s