(Mandelbrot fractal ) Mandelbrot fractal is a well-known image created from a Mandelbrot set (see Figure 15.13a). A Mandelbrot set is defined using the following iteration:
c is a complex number and the starting point of iteration is Z0 = 0For a given c, the iteration will produce a sequence of complex numbers:
It can be shown that the sequence either tends to infinity or stays bounded, depending on the value of c. For example, if c is 0, the sequence is {0 ,0 ,…..} which is bounded. If c is i, the sequence is
which is bounded. If c is 1 + i the sequence is
which is unbounded. It is known that if the absolute value of a complex value Zi in the sequence is greater than 2, then the sequence is unbounded. The Mandelbrot set consists of the c value such that the sequence is bounded. For example, 0 and i are in the Mandelbrot set. A Mandelbrot image can be created using the following code:
The count(Complex c) method (lines 23–32) computes z1, z2, . . ., z60. If none of their absolute values exceeds 2, we assume c is in the Mandelbrot set. Of course, there could always be an error, but 60 (COUNT_LIMIT) iterations usually are enough. Once we find that the sequence is unbounded, the method returns the
iteration count (line 28). The method returns COUNT_LIMIT if the sequence is bounded (line 31).
The loop in lines 8–9 examines each point (x, y) for -2< x < 2 and -2 < y < 2 with interval 0.01 to see if its corresponding complex number c = x +yi is in the Mandelbrot set (line 10). If so, paint the point black (line 12). If not, set a color that is dependent on its iteration count (line 15). Note that the point is painted in a square with width u and height 1. All the points are scaled and mapped to a grid of 400-by-400 pixels (lines 14–15). Note that the values 77, 58, and 159 are set arbitrarily. You may set different numbers to get new colors.
Complete the program to draw a Mandelbrot image, as shown in Figure 15.13a.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.