Images relating to the Mandelbrot Set are all over the Internet. Producing yet another program to create images from the calculation of this set is therefore nothing remarkable. Nor is it particularly difficult. Yet it is worth doing for several reasons.
Firstly, however much we see new examples of such images they grab the attention. Most Mandelbrot-related images are instantly recognisable as such, yet they are all distinctly different from each other. In fact, once you starts to zoom into local regions of the Set boundary there is a fair chance that you are producing images that in detail are unlike any produced before because there is an infinite amount of variation to be explored. It is that knife-edge between randomness and order that seems to be especially intriguing to the human brain.
A second reason for programming this algorithm is that it does illustrate a number of useful techniques, and also some interesting algorithmic ideas. The fundamental algorithm underlying the calculation is fairly simple, but the results are visually rewarding. I suggest that these are good characteristics for a motivating learning exercise.
These exercises also start to open up a much wider field of investigations into fractal images (for example, the closely related Julia Sets, which are perhaps not so familiar to most readers as the Mandelbrot Set). The mathematics of fractals are very much bound up with an important field of complex dynamics and chaos theory. The complexity of fractal images on the boundary between order and disorder is related, for example, to the difficulty of predicting the weather even when we know all the initial conditions and the precise equations governing their evolution into the future. Fractal images are a great way to illustrate some of the maths (and mathematically inclined people love them more than most) but for the mathematician they are not the real point.
But is it Art?
You might well argue about whether the images generated are truly "art" (though they are certainly decorative and have complex layers of associated meaning to the mathematically inclined), Nevertheless, the only creative decisions made by the programmer are choices of colours to encode the numbers coming out the calculation, followed, usually after much exploration, by the selection of certain expanded regions of the total image for their visual interest.
Everything else is the result of mathematics - pre-defined and unchangeable, so it is arguable that we are not actually creating anything.
On these grounds, of course, we might argue about whether photography can be art (and many people have done so). Much photography is also a matter of conscious selection of images from pre-existing scenes which, however, I think can attain the status of art when the act of selection and manipulation of the image introduces additional layers of meaning and significance for photographer and viewer. These arguments have less force when exploring the Mandelbrot Set: it really is perhaps just too easy to find visually arresting images (but it is less easy than you might think to arrange a colour coding that keeps to the subtle side of vulgarly psychedelic - I am still trying).
In spite of such considerations people do not seem to tire of more Mandelbrot images, and I can understand that view: exploring the Set is always addictive.
So, what is the Mandelbrot Set?
First of all what is a set. In the classic definition of Georg Cantor it is a "Gathering together into a whole of definite distinct objects of our perception or of our thought." and it is one of the most fundamental concepts in mathematics. In this case, the Mandelbrot Set is a collection of complex numbers which have the property that when a certain operation is iterated on a member of the set, the sequence of complex numbers that is generated always stays finite. For complex numbers outside the set, the iteration eventually diverges away to infinite values. (An iterated operation means that we apply a certain operation to the first number we thought of, get a result, apply the same operation to that number, get a result, apply the same operation to that number ... and so on and on and on. The behaviour of such sequences is connected to whether we can use mathematical equations to predict the future, e.g. the weather, by jumping forwards in small time-steps.)
A complex number is made of two parts (usually called the real and the imaginary parts - these are just arbitrary labels, don't get hung up on them) and you can, if you wish just think of this special type of number as a pair of ordinary numbers that always travel together, say (3.23,-4.123), which you work with according to certain well-defined rules. Here, the first of the par is the "real" part and the second the "imaginary" part. We can therefore, if we wish, think of this as a coordinate pair and represent a complex number as a point on a 2D plane, just by using the the real part to define the X-coordinate the imaginary part to fix the Y-coordinate. You have to be able add, subtract, multiply and divide numbers and complex numbers come with a set of rules on how we do this. It happens that the easiest way to remember the rules is to think of the number with the imaginary part multiplied by the square root of -1. So we might write our complex number as 3.23+4.123i (where "i" here means the square root of -1). There is, of course, no real number that when multiplied by itself gives -1 and hence complex numbers sometimes give a lot of grief to novice mathematicians: how can you do valid calculations with a number that does not exist? Don't worry! Mathematicians have proved that if you use the rules properly you will never generate a contradiction and complex numbers turn out to be fantastically useful for solving many difficult problems. (We could not calculate the physics of atoms without complex numbers.) In fact, mathematicians sometimes talk about the "magic" of complex numbers because of the way they make difficult problems easy.
In illustrations of the Mandelbrot Set it is often conventionally the dark region of the plane which represents the Set itself (this is where iteration of the associated complex number does not diverge away to infinity). Colours are often used in the region outside the set boundary to encode the number of iterations required before it is clear that we are on a diverging track.
The mathematically interesting features of the Set are that a high degree of complexity arises from an exceptionally simple operation: we take our original complex number, c, and apply the iteration zn+1 = (zn)2+c, where our first iteration is with zo=0 and so z1 = 0 + c2 , We then count the number of iterations until the distance of z from the origin reaches a value that allows us to conclude that c is definitely not in the Mandelbrot set, or we reach an upper limit on the number of iterations we are prepared to tolerate, say 200 or so (in which case we conclude that c is probably in the Mandelbrot set). Having counted the number of iterations to diverge to an outer boundary, we use that the determine a colour and apply that colour to the point on the image plane that represents c. The image on this page, if you zoom in enough, always has a black filament running through the most complex areas. The images also have the property of self-similarity - zoom into small regions and they look just like larger regions. Zoom in again, as much as you like and you will get the same characteristics.
The boundary of the set - on one side in, on the other out - is fractal. However much you zoom in it still has a highly irregular shape. The Set is, however a connected region, from any point in the Set you can make a track to any other point in the Set always staying within the boundary.
Programming the Calculation
Most of the programming complexity in the program (my first draft can be downloaded here) is associated with control issues: I wanted to have an interactive tool to explore the image space. So, I would like to be able to draw a box within an image and zoom in to that zone, and I also wanted to be able to progressively back-out so I could then go into different zones. These are useful techniques to learn.
The program responds to the following keyboard operations, and mouse movements.
Left mouse button |
Press and drag to outline a white box as a sub-region of the developing image. On releasing the button, the iteration restarts zoomed on that sub-region. The height/width dimensions of the box are constrained to the relative dimensions of the canvas. |
's' | Press and release the 's' key to save a copy of the current image. |
'z' | Press and release the 'z' key to return to the initial state. |
'b' | Press and release the 'b' key to return to the previous zoom level. |
'f' | Press and release the 'f' key to go forward to a higher zoom level previously calculated. |
'i' | Zoom in on the center of the current image. |
'o' | Zoom out from the center of the current image. |
'u' | Press and release the 'u' key to increase the number of iterations used before deciding that the iteration is not diverging. (This can increase detail at high levels of zoom on the Set boundary. |
'd' | Press and release the 'd' key to decrease the number of iterations used before deciding that the iteration is not diverging. |
Extension Ideas
I would also like to explore some extensions to this program, which might include recording the track taken into a small region of the image, and then automatically re-running a fine-grained sequence of zooms to generate a video.
With every point on the Mandelbrot Set image, we can also associate another fractal diagram derived from the related Julia Set. It might be interested to be able to click on the Mandelbrot image to immediately produce the Julia Set.