Write a java program that generates the Mandelbrot set. You will implement Complex numbers as a class, with its own set of methods.
The Mandelbrot set studies whether points on the complex plane tend toward infinity or not under repeated quadratic operations. Your program will output an image representing a region of the complex plane, showing how many times the quadratic operation was repeated against each point until the operation "reached infinity". Your program must adhere to the following specifications:
dx = ( right - left ) / (xdim - 1) dy = ( top - bottom ) / (ydim - 1)This first step gives us a complex number to pass to the Mandlebrot recurrence equation. It could be implemented as a method
z(n+1) = z(n)*z(n) + cwhere z and c are complex numbers and c is a the point from the pixel array that you mapped to the complex region, z(n) is the output of the function from the last iteration, z(n+1) is the z(n) input to the function in the next iteration, and n keeps track of the number of iterations. When z gets far enough from the origin, that is, when z.modulusSquare() > Rmax, you color the pixel with the value n. If n reaches MaxColor (that is, 255) and you're not getting anywhere, color the pixel 0. You will conclude that a complex number tends to infinity if its modulusSquare exceeds Rmax.
There are 3 possible outcomes in each iteration:
That's the Mandelbrot set!
P2 xdim ydim 255 c11 c12 c13 ... c1xdim c21 c22 c23 ... c2xdim ... cydim1 cydim2 ... cydimxdim
where 255 represents the maximum greyscale value;
cij represents a greyscale value between 0 and 255.
Please enter x and y dimensions: 160 120 Please enter left, right, bottom, top: -0.74758 -0.74624 0.10671 0.10779
view output (160x120)
view output (40x30)
Please enter x and y dimensions: 160 120 Please enter left, right, bottom, top: -1.254024 -1.252861 0.046252 0.047125
view output (160x120)
view output (40x30)
| Left | Right | Bottom | Top |
|---|---|---|---|
| -2.25 | 0.75 | -1.5 | 1.5 |
| -0.19920 | -0.12954 | 1.0148 | 1.06707 |
| -0.95 | -0.88333 | 0.23333 | 0.3 |
| -0.713 | -0.4082 | 0.49216 | 0.71429 |
| -1.781 | -1.764 | 0.0 | 0.013 |
| -0.75104 | -0.7408 | 0.10511 | 0.11536 |
| -0.746541 | -0.746378 | 0.107574 | 0.0107678 |
| -0.74591 | -0.74448 | 0.11196 | 0.11339 |
| -0.745538 | -0.745054 | 0.112881 | 0.113236 |
| -0.745468 | -0.745385 | 0.112979 | 0.113039 |
| -0.7454356 | -0.7454215 | 0.1130037 | 0.1130139 |
| -0.7454301 | -0.7454289 | 0.1130076 | 0.1130085 |
All the work submitted here should be based on your own (or the pair's) effort. Plagiarism of other's works e.g. those found on the web, is considered cheating.
submit cmps012a-ap.w05 prog5 Mandelbrot.java
You can submit more than once, for example to update your
previous submission with new/improved code.
Each person should separately submit a log file for each programming assignment.
Refer to the programming guide link for specifics on requirements and grading guide.
You can change your output into a color image using the xv program on the suns. You don't need to change anything in your program. Select the Windows button, then select color editor. On the color editor popup window, click on the random button. Each time you change the color map, your image will have a new set of colors!
On windows, you can do something similar. First, convert the pgm image into a gif or jpg image using some image conversion utility such as Imagemagick . View the image file using photoshop. Under the Image tab, first select mode and change to indexed color. Under the Image tab again, select mode again, and this time select color table. There are several predefined color tables you can pick from to alter the colormap of your image.
Color versions of session 1.
Color versions of session 2.