Introduction

The Mandelbrot set is a complex mathematical object first visualized by mathematician Benoit Mandelbrot in 1980. The set is enormously complex — it is said by some to be the most complex known mathematical entity.

The Mandelbrot set is an example of a kind of mathematics that was always possible in principle, but that only exists in a practical sense because of the advent of cheap computer power. In modern mathematics, computers have changed everything but the basics. Relatively simple conjectures can be verified or falsified in a flash, applied mathematics has been completely transformed, and there is now what can only be called "recreational mathematics" — like the Mandelbrot set, in essence an explorable mathematical landscape.

Algorithm

Notwithstanding its complexity, generating and rendering the Mandelbrot set is relatively easy:

Establish a two-dimensional complex plane, extending from about -2.0 to +1.0 on the real axis and about -1.5 to +1.5 on the imaginary axis.

At each point within the plane (using steps determined by the intended graphic resolution), perform this iteration: (1) $Z \rightarrow Z^2 + C$ Where Z is a complex value initially set to zero, and C is a complex coordinate: (2) $C = x + yi$ where $x,y$ represents a Cartesian two-dimensional coordinate in Mandelbrot space.

where $x,y$ represents a Cartesian two-dimensional coordinate in Mandelbrot space. For each desired $x,y$ coordinate, repeat the iteration shown in (1) until the $Z$ value either departs toward infinity (in which case that coordinate is not part of the Mandelbrot set), or it orbits perpetually without diverging (in which case it is), as shown in Figures 2 and 3.

In the simplest Mandelbrot generators, each coordinate in the space is tested for membership in the set based on the iteration shown in (1) not diverging toward infinity. Those coordinates belonging to the set are given a distinctive color and the canonical Mandelbrot set shape appears (background of this paragraph). The more elaborate Mandelbrot set generators (like the one on this page) assign different colors to the points on the periphery of the set, based on how quickly they diverge toward infinity.

Execution speed versus image quality

Generators that assign colors use the count of iterations before divergence toward infinity as an index into a table of colors, then assemble a graphic image composed of the colors.

Generator design is a classic computer science problem. At one extreme, a generator can be made very fast by allowing only a few iterations (and colors). At the other extreme, a very high-quality image results from a design that allows many iterations, each of which has an associated color, but at the expense of running time.

The simplest Mandelbrot generators are very simple indeed. Here's a minimal Python example:

#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2013, P. Lutus http://arachnoid.com # Released under the GPL http://www.gnu.org/licenses/gpl.html from numpy import arange # dimensional parameters for the set yl = - 1.2 yh = 1.2 ys = .05 xl = - 2.05 xh = 0.55 xs = 0.03 def mandelbrot(c): z = 0 for n in range ( 10 ): z = z*z + c if( abs (z) > 2 ): return '.' return '*' s = '' for y in arange(yl,yh,ys): for x in arange(xl,xh,xs): s += mandelbrot( complex (x,y)) s += '

' print(s)

Here is the program's plain-text output with the default settings:

....................................................................................... ....................................................................................... ..............................................................**....................... ...............................................................*....................... ................................................................*..**.................. ................................................................***.................... ...............................................................****.................... ...........................................................***********................. ............................................................**********................. ...........................................................***********................. ...................................................*.......***********..........*...... .................................................****..********************.....*...... ................................................***********************************.... .................................................********************************...... ...............................................**********************************...... .............................................************************************...... .............................................*************************************..... ..........................**......*.........*****************************************.. ............................***********.....***************************************.... ............................********************************************************... ..........................*********************************************************.... .....................*....*********************************************************.... ......................************************************************************..... .....................***********************************************************....... ..*****************************************************************************........ .....................***********************************************************....... ......................************************************************************..... .....................*....*********************************************************.... ..........................*********************************************************.... ............................********************************************************... ............................***********.....***************************************.... ..........................**......*.........*****************************************.. .............................................*************************************..... .............................................************************************...... ...............................................**********************************...... .................................................********************************...... ................................................***********************************.... .................................................****..********************.....*...... ...................................................*.......***********..........*...... ...........................................................***********................. ............................................................**********................. ...........................................................***********................. ...............................................................****.................... ................................................................***.................... ................................................................*..**.................. ...............................................................*....................... ..............................................................**....................... .......................................................................................

Figure 4: Too few iterations/colors

resulting in bands Figure 5: Sufficient iterations/colors

The most complex Mandelbrot generators accommodate any number of iterations/colors, permit the user to move around within the set and magnify selected areas, and show sometimes beautiful images. Such a generator is built into this page.

Browser Issues

Because the generator runs under JavaScript, I caution my readers that they need to install a modern browser — a list topped by Google Chrome and Mozilla Firefox. For various technical reasons, most other browsers won't be able to run the generator satisfactorily, and most versions of Microsoft's browser won't be able to run it at all (more technical detail appears below the applet).

Color Banding

There is an aesthetic consideration in Mandelbrot set generation: if the generator is configured to allow too few iterations/colors, it will run fast but its images won't be very attractive. When too few iterations are allowed, the transition from one color to another shows up as a series of rather homely bands (Figure 2). The remedy is to increase the number of iterations/colors and accept slower rendering (Figure 3).

Fractal

The Mandelbrot set has the fractal property of self-similarity. As one explores the set, one encounters familiar shapes at increasing magnifications, and examples where a large structure is composed of much smaller components that resemble the large structure. Then it turns out that those smaller structures are composed of yet smaller structures of the same shape. It's initially shocking to increase the magnification from the default of 0.4 to several billion and discover the same kinds of shapes at all magnifications.

Chaos Theory

The Mandelbrot set also has properties of a chaotic system, a system that, even though it appears random in its behavior, is actually a deterministic system that is extraordinarily sensitive to initial conditions. Figure 3 shows how a complex orbit sometimes takes coordinates that seem unpredictable before shooting off toward infinity. The point is that the Mandelbrot set, although very complex, is entirely deterministic — it always produces the same results for given inputs.