Exploring the Mandelbrot Set

The Mandelbrot or M set is considered to be the most complex object in mathematics and probably the most complex object ever seen. The Mandelbrot Set is an infinite object that always looks similar but never repeats!
But at the same time, it is generated by an amazingly simple formula,

Z(n+1) = Z(n) * Z(n) + C
where C is a complex number which acts as a viewpoint in the XY plane
and Z(0) = 0

Complex numbers basically consist of a real and imaginary part. The imaginary part is suffixed with a "i" whose value is sqareroot of -1. It is interesting to note that

i * i = -1 

which means that the square of an imaginary number is negative.

With respect to the M set, the real part represents a point on the X axis and the imaginary part is a point on the Y axis.

From the above equation, depending on the value of C, Z will either diverge (shoot to infinity) or converge (move towards zero). For eg,

0.5 * 0.5 = 0.25
0.25 * 0.25 = 0.0625 and so on
The above indicates convergence and something like

2 * 2 = 4
4 * 4 = 16
16 * 16 = 256
256 * 256 = 65536 and so on 
The above indicates divergence.

The sequence of all values of Z that converge form the Mandelbrot set. The points in the M set are coloured black while others with a color which is relative to the number of iterations taken to test for divergence.

This proggy is an implementation of the Mandelbrot set.

Use the arrow keys to move around the screen and press the "spacebar" to zoom in at the selected point. The "minus" key can be used to zoom out. You can keep zooming in on every point on the object and discover that the image keeps getting clearer and more beautiful with each zoom.

Included in the tar archive along with the source is a statically compiled binary which should most probably work without problems. The program works on a resolution of 800x600 and 256 color mode.

To compile the program,

gcc -o mandel mandel.c -lvga
AttachmentSize
mandelbrot.tar.gz343.16 KB