|
|
While browsing various web sites containing fractal art or other content about fractals, I noticed it is difficult to find a site that explains how these images are created. Therefore I thought I would include the basic algorithm for generating Julia and Mandelbrot set fractals on this site. If you are more interested in the mathematical aspect you should find a good book or web site on fractals or chaos theory. A good introduction is the classic: "The Fractal Geometry of Nature" by Benoit B. Mandelbrot (W.H. Freeman and Company, 1977). Another book that I found enjoyable and providing a good historical introduction is "Chaos: Making a New Science" by James Gleick (Viking Penguin, 1987).
The algorithms for calculating Julia and Mandelbrot sets are similar. The main discussion that follows covers Julia sets but the changes needed for calculating the Mandelbrot are given at the end. Since these algorithms are based on complex numbers we will start off with a review of some of the basic math.
Complex numbers consist of a real and imaginary component. For example consider the complex number z below, which has a real number component x and an imaginary number component yi.
Imaginary numbers are a mathematical invention to account for the problem of taking the square root of a negative number. Imaginary numbers include the letter 'i' as a factor to represent the square root of -1.
For example, to obtain the square root of a negative number, the 'i' can be factored out.
In the equation above, the y factor of yi is a real number just like x. Complex numbers can be manipulated like binary numbers with special attention given to the factor i. Operations on complex numbers usually result in a complex number. For example consider the multiplication of the two complex numbers below.
The real and imaginary components of complex numbers can be used to represent different dimensions. For example, complex numbers can be plotted on the Cartesian plane with the real component along the x-axis and the imaginary component along the y-axis. The following figure shows the complex number z = 2+4i plotted on the Cartesian plane.
Cartesian coordinates can also be used to represent location on a computer screen. Computer images are composed of numerous small squares called pixels. Each pixel can only be a single color (at any single moment). Typically there are about 70 or more pixels per inch in either the x or y direction. When magnified, a computer image looks like a mosaic of colored tiles. However when viewed as intended, the eye perceives the image as a smooth continuous picture (usually). The image below shows a Mandelbrot set with an enlargement of a small area demonstrating the mosaic appearance of pixels.
Mandelbrot and Julia set fractals are constructed using functions of complex numbers. One of the simplest and most commonly used functions is:
where both z and C are complex numbers. This is the equation used to generate the preceding Mandelbrot set image.
When calculating Julia sets, z is a variable representing a Cartesian coordinate within the image and C is a constant complex number. C does not change during the calculation of the entire image. However, when different values of C are used, different images will result.
The first step to calculate the image is to choose an equation and a value for the complex constant C and then plug a screen coordinate value (x,y) into z. The ultimate outcome will be to assign a color to the pixel that maps to the given (x,y) coordinate. Notice that I said first step. The output of the function f(z) is not used directly to determine the color of a given pixel but it is the start of the process.
The second step is to calculate the norm or size of the result of f(z). Processing the function f(z) on the given values of z and C yields another complex number. The norm of this number is calculated using the equation below. The value of the norm will be a real positive number. The value of the norm is then compared to another number called the blowup parameter. If the value of the norm is greater than the blowup parameter we assign a value of zero to the pixel to represent the color. Otherwise if the norm is less than or equal to the blowup number, the value of f(z) will be substituted back into the equation as the next value of z. Next the norm of f(z) is again calculated and compared to the blowup parameter. This time if the norm is greater than the blowup parameter a value of 1 is assigned to the pixel, but if it is not, the new value of f(z) is substituted back into the equation in the place of z. This process is repeated over and over until a norm is greater than the blowup parameter or the number of cycles or iterations exceeds some maximum number. The number of iterations that have occurred until the norm exceeds the blowup parameter will be used to assign a color to the pixel. The number assigned to the pixel will be an integer value between zero and the maximum number of colors used to make the image.
Finally the process just described for a single pixel is performed on every pixel in the image, one pixel at a time.
Typically the maximum number of colors is 256, which is mainly because this is a convenient size used in computer image formats, however it could be anywhere from 2 to the largest number the computer can handle. Each integer will represent a different color and these will be linked in some kind of table or palette. For example a value of zero may represent black, one could be violet, two could be red, and so on. Many image formats or file types like bitmaps store an image as an array of integers representing the pixels and a color table, which tells the computer which color to map to the indexes in the image array.
The colors used in the table or palette can have a big effect on the way an image appears. In the figure below, each image has the same integer values assigned to all the same pixels but the color table has been changed.
The calculation of a Mandelbrot set is similar. The difference is in the values that are substituted into the equation. In the equation for f(z) the pixel coordinate (x,y) is substituted into the complex number C and (0,0) is substituted for a starting value of z. After the first iteration, the value of f(z) is substituted for z just like when calculating the Julian set.
It should be mentioned that this is the original coloring algorithm used to display fractals. It is more common today to see fractals made with algorithms that can generate much larger numbers of colors so that the images appear smoother or in other words, the changes in color usually appears more continuous. If I get time I will try to include them on this page.
| Home |
| FractalDesign.net Copyright © Steven Robles 2004-2006. All rights reserved. |