(Mandelbrot fractal) Programming Exercise 15.20 displays Mandelbrot fractal. Note that the values 77, 58, and 159 in line 15 in the MandelbrotCanvas class in Programming Exercise 15.20 impact the color of the image. Revise the program to let the user enter these values from text fields dynamically, as shown in Figure 17.25a.
Ref:
(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
For 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{0, i, - 1 + i, -?i, -?1 + i, i,…}, which is bounded. If c is ?1 + i, the sequence is {0, 1 + i, 1 + 3i, …},which is unbounded. It is known that if the absolute value of a complex value
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 < 2and -?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.