Thursday, September 11, 2008

Mandelbrot Set

The Mandelbrot Set is a great introduction to understanding fractals. A fractal is defined as an object with repeating patterns at different scales. Nature makes the best fractals, and they are everywhere you look once you develop an eye for them - clouds, trees, rivers, moutains, leaves, circulatory and nervous systems, etc. The Mandelbrot Set is a computer generated image that also displays self similarity at different scales along with striking beauty. Programming the algorithm to create an image of the Mandelbrot Set is a fun way to test out a new programming language. This complicated mathematical object is actually created by a rather simple procedure. For some complex number c, we start with z = 0 and evaluate subsequent z's by the iteration



z = z^2 + c.

If z remains finite, even after an infinite number of iterations, then the point c is a member of the Mandelbrot set. Since infinity is a very big number, it wouldn't be practical to iterate the equation infinity times so a smaller number like 255 iterations is enough for the job. The points c that are a member of the set get colored black. The points not a member of the set can be colored and given a brightness proportional to the number of iterations taken to escape.

To program the algorithm, you need to think of a square plane of pixels on your computer screen to be the complex plane, where each pixel on that square represents the coordinates of a unique discrete complex number given by the the x and y location of the real and imaginary axis respectively. For each pixel, you need to determine its location on the complex plane and then using that value, seed the above equation with it as c. Then you enter a loop and continuously reiterate that equation until you reach some preset maximum number of iterations like 255. If at any time during the loop, the magnitude of z is greater than 2, you can break out of the loop because you know that seed value doesn't belong to the Mandelbrot Set, and you can assign a color value to that pixel based on how many iterations it took to exit the loop. Otherwise, the seed value is part of the Mandelbrot Set and you can color it black. You do that for every pixel in your square, and the Mandelbrot set appears!

Following are some screen shots of the Mandelbrot Set from a program I recently wrote in Java using the SWT libraries. I added capabilites so I could click on a part of the Mandelbrot Set, triggering the program to zoom deeper to reveal more details. By the way Mandelbrot means "almond bread" in German.












1 comment:

Anonymous said...

Yea, yea,.....
add some graphics cards to your "super" puter, use CUDA or Brooks and give me some benchmarks.. Stop the infantile crap and let us get on with some serious work!...Did not appreciate your hack 5--- How to highjack a visual server crap. Get real!


Happy holidays fromj sunny Puerto Rico again....
Jose, the beachbum,
...still celebrating the Christian Holidays till Jan 6 here..You are invited to a sunny tropical beach in a medieval society......
Tsunamy size waves are super cool. Interested in doing so some fluid dynamics simulations in your rig???....We have some use for this kind of stuff here.....billion plus contracts wating, ;)