Art with Complex Numbers!

  • 0

Art with Complex Numbers!

Category : Uncategorized

Complex numbers are numbers made up of a real part and an imaginary part containing i, the square root of negative 1. They’re usually expressed as z = a + bi, where a and b are real numbers, as in z = 2 + 3i. In fact, every number you’ve used is a complex number, but a real number like 5 is expressed as 5 + 0i, meaning it has no imaginary part. It reminds me of the character in the Moliere play who was tickled to learn he had been speaking prose his entire life without knowing it.

When you learn about complex numbers in a traditional math class you seldom get to do much with them, because it takes a lot of algebra to multiply them together (think FOIL) and forget dividing them. Your textbook says they’re used in such fractals as the Mandelbrot set but it never tells you how.

The great thing about using computers in math class is you can write functions to operate on complex numbers and (once you’ve ensured your code works) easily transform them. Every point on the plane is given a coordinate, not unlike the (x,y) coordinate system you see in Algebra class. In fact each point (x,y) in the traditional Cartesian coordinate system can be expressed as a complex number in the complex coordinate system, as z = x + iy:

 Here’s where you start learning about transformations. Obviously, adding and subtracting complex numbers corresponds to translating a point. Multiplying complex numbers corresponds to rotating. Squaring complex numbers is particularly interesting, because of the patterns that result. In the figure below I created a grid inside a tiny part of the coordinate grid. The blue lines are one unit apart, so we’re really just dealing with the points between 0 and 1 horizontally and 0 and i vertically.

The black grid in the lower right is composed of a bunch of points, and when they’re put into a function they’re transformed into the red points. In this case, I created a function to square a complex number like this:

def cMult(a,b):
    '''Returns the product of two complex numbers'''
    return [a[0]*b[0]-a[1]*b[1],a[1]*b[0]+a[0]*b[1]]

Of course, multiplying a number by itself is squaring, so this will square the complex number a:

>> a = [1.0,1.0]
>>> cMult(a,a)
[0.0, 2.0]

In the graph, the complex number a = 1.0 + 1.0 i is the top right corner of the black grid. In the red grid, you can see it maps to the point 2i, at the top of the screen. The complex version is 0 + 2i, and that’s why the output says “[0.0, 2.0]”

 Santa Clara University Professor Frank Farris took this visualization one step further in his book Creating Symmetry. Instead of transforming a list of points, he transformed the pixels in pictures he took of flowers, fruit and other food. He took pictures like the one below at left, and transformed each pixel (which has a position on the screen just like points do) to another position using more and more complicated functions, resulting in surprisingly beautiful patterns like the one below at right:

The formula Farris used to map the pixels of the picture of the dahlia is

Once you’ve written the code for “take the coordinates of a pixel, run it through this function and place the color of that pixel at the new location” the rest is just giving the program new functions. I wanted to copy Farris’ beautiful wallpaper pictures and found this formula in Chapter 10:

Which leads to mapping the example color wheel to this fantastic rotation/translation design:

The equation looks ugly but once we’ve written the code for “e to the power something” and declared what the variables m and n are, the computer will do the rest. This is the output I got putting my dahlia into that function:

 Lavender’s nice, too:

Like I always say, Math is art!

My code is on github.


Leave a Reply