Generating fractals

Introduction

    In this section we show what is behind generating fractals. While looking into a fractal picture we can image a flat surface comprising a large number of points. Each point has coordinates x xand y, and these determine its position in the picture. The picture has the size of the dimensions of the screen in which we will display it.

    For generating a fractal we need a function. Using this function we receive two new coordinates for two input points (x and y coordinates of a point). At the beginning of the calculation of the function, let's have a selected starting point. Then, via iteration of this function we obtain new coordinates x, y. In this way, the point is "moving?" to the new positions given by the function. To iterate? the function means to apply it again and again. In this way, we receive a set of coordinates for the selected point.

    If we proceed in this way further, then two things can happen. Firstly: the point is moving "around? "(meaning, that after a certain number of iterations we obtain the same value which we had already) and thus will never leave the set display window. Or: after a certain number of iterations, the point leaves the display window and will not be visible to us any more. Using a number of iterations we can define the number and layout of color in a picture. If the point will never leave the screen, we display this point in our selected color. The points, which never leave the screen we then paint the same color. In the case where the point leaves the screen we then use the number of iterations for defining the color of the given point. For instance: if the point leaves the screen in the first iteration, we paint it blue, if after the second, then red, and so on. For receiving elegant, fine shading of fractals, we select individual shades of some color.

    The following picture depicts the movement of the point marked by the zero function of the Mandelbrot set. Each of the numbered points shows a new position after a further iteration. After the first iteration of function, the point moved to the position 1, after the second to position 2, and so on. The point left the screen after the fifth iteration, so it is painted in the color with index 5.

    In the case of the Mandelbrot set, pixels inside a unit will never leave the display box. The following picture depicts the iteration of a point inside this limit. This point will never leave the display box, however we iterated it, because after iterations of points 0. 1, 2, we obtain again the point 0.

    Because we must iterate each point in an image, and the fact that there are a lot of such points the calculation of fractals is a highly time-consuming process .

Example :

    Let us have a function and the first point with coordinates (2,3). Let us use our function, and we obtain the new coordinates (5,7). This point is still in the display window, so let us continue in the iteration. After the following iteration we receive (2,3). But we started at this point. If we iterated again we would again receive the point (5,7) and then (2,3), and so on. This point will never leave the display window Therefore, we now take the original point, that is (2,3) and paint it, say, black. In this way we defined that those points which never leave the display window are black.

    Let us take the following point with the coordinates (3,3). After iteration, say, we obtain (9,11). We iterate again, at which we obtain the point (125, 77896). This point is outside our display box. Overall, we did two iterations until the point left the display box. Therefore, we paint the point (3,3) in the color indexed 2. All points, which leave the display window after two iterations, will have the color indexed 2.

    Let us continues further, until having painted every point in the display window. The resulting image, which is obtained, is a fractal. Which sort? That depends on the selected function. If we use some function, we can get the Mandelbrot set, if we use another function, we can obtain another fractal. We can choose from a huge number of functions, and therefore, there are also an infinitely large number of fractals.

Generating a fractal

    In this section, we proceed up to a specific calculation of fractals. For understanding the following lines you will need mathematical knowledge in the field of complex analysis. In the above section we said that a fractal is established through iteration, but did not show the function by which a fractal is established.

    The first things that must be to known are complex numbers. Any complex number contains two parts: the first part a real number, for instance: 1, 1.4, 1/6, and so on. The second component is an imaginary part, represented by a real number multiplied by i: 4i, 3.8i, and similar. Where i^i=-1(i to 2 is equal to minus one). Examples of complex numbers: (4=i), (2.4 + 3.1i), (145 ? 0.456i). The complex number (2+3i) can be written as (2,3). Every point that has two coordinates x and y, which can be written as (x,y).

    Complex coordinates, used for generating fractals, are not coordinates of the points, which they represent. Coordinates of points are always bigger than zero, and are lower than the limit of the display box. The range of coordinates, which we use for calculation, will depend on the fractal, but mostly is from the range: x <-2,2> and y <-1.5, 1.5>. So, the complex numbers, used by us, are mostly small fraction numbers. The range of coordinates x, which is 4 (and in the case of y it is 3), represents virtual coordinates, and it is necessary to convert this into display box coordinates. In the calculation, we are working with a large amount of small numbers.

The addition of complex numbers is carried out in the following way: a,b,c a d  R

    (a + bi) + (c + di)= a+c + bi-d i=  (a+c) + (b+d)i,

This means :   real parts are added separately, and imaginary parts are added separately, too.

Multiplication :

    (a + bi) * (c + di)= a*c + bi*c + a*di + bi*di= (a*c)-(d*d) + (bc + ad)*i

as well as (i^2)=-1, the relationship bi*di can be written as: b*d (i^2) = -1*b*d.

Division though it is not used in the case of fractals, we state it for the reason of completeness:

    (a+bi)/(c+di) =[(a*c + b*d) + i(c*b - a*d)] / (c^2 + d^2)

Now, after a revision of complex numbers, we can start to generate a fractal using a selected function.

Example :

    Let's take the function for calculation of the Juliet set. The relevant function is f(z)=z^2+c, where c is a simple complex number affecting the resulting fractal. Let's take c number (1+1i), and the starting point (2+1i).

f(z) = f(2+1i) = (2 + 1i)^2 + (1 + 1i) =
                      = 2*2 + 2*1i + 2*1i + 1i*1i + 1 + 1i =
                      = 4 + 2i + 2i + 1(-1) + 1 + 1i =
                      = 5 + 5i -1
                      = 4 + 5i

After the first iteration, we receive number (4+5i). Let us iterate further

f(z) = f(4 + 5i) = (4 + 5i)^2 + (1 + 1i) =
                        = 4*4 + 4*5i + 4*5i + 5i*5i + 1 + 1i =
                        =16 + 20i + 20i + 25(-1) + 1 + 1i =
                        =17 + 41i - 25 =
                        =-8 + 41i

After the second iteration, we obtain (-8,+41i). We continue in this way further, testing at each stage, whether we are not out of the display box. Every time we test whether the point leaves the circle with the radius 2. We can prove that if a point leaves this circle, it will go to infinity, so we simply stop the iteration. The number of iterations that we do before a point leaves the circle determines the color of the original point.

    For the number of iterations we must set a limit. Because, for example, the points inside the Mandelbrot set will never leave the display box, we would iterate "'for ever'". Therefore, we must set the maximum number of iterations to N. If a point is still inside our circle after even N iterations, then we accept it that it is in the set?, and, we assign to it the index of the maximal color. A larger number of iterations will increase the detail of the image, however, the time required for calculation could be too long. After processing all points, we get the fractal. Using a different equation, we obtain a different fractal. The Mandelbrot sets are generated in the same way as the Juliet sets, with the difference that the value c is different for each point. In generating the Mandelbrot set, the value c is constant for each points. We start with 0. Then, we square it and add the value c. Then, we square the new value and again add the value c. In the end, when we leave the display box or exceed the iteration limit, we paint the relevant point in the respective color. In the program  Fractint we can design our own formulas.

Julia Fractal

$$$APPLET

Applet Julia Fractal. Author : Michal Vanek

Mandelbrot set

$$$APPLET

Mandelbrot set. Set a rectangle for zoom. One mouse click - reset to default zoom. Author Marián Orešanský Hlavačka Adam
Source code
Copyright (c) 1999-2017 Juraj Štugel. www.netgraphics.sk