Mandelbrot Sets

Loosely based on a C language program created at uchicago.edu.

Mandelbrot sets are images of self-similar repeating structures (i.e. fractals).

To explain this code it will be necessary to introduce a few extra concepts. The first are complex numbers:

 complex.py 1 x = 1.0j 2 print x,x**2,x**3,x**4 ```\$ python ./complex.py 1j (-1+0j) (-0-1j) (1+0j) ```

Complex numbers are special values are built from familiar real numbers, and special imaginary numbers. Thus, the operations on complex numbers allow you to perform mathematical operations on pairs of numbers. We don't expect you to understand them deeply, we just want you to grasp two points:

1. Complex numbers are useful for certain computations
2. Python supports them

If you want, you can think of the calculation in pixel as just a magic box.

The next bit of magic is the "bmp" module that we have provided. It allows you to make a bitmapped image from a two-dimensional array of values. As you become more advanced in the art of programming you should eventually be able to understand how it works. For now, just use it.

What we really want you to understand from this program is the way it uses parallel programming. Rows of the image are considered as tasks. A single master process hands out tasks to the worker processes, and as the workers finish a task they come back and request another.

This way of doing things keeps all the workers busy all the time, even when the difficulty of the tasks is variable.

Possibly a simpler calculation could have been used to illustrate this style of programming, but this one makes a really cool picture. :)

 prev next