Question: In this Final Course Project for PRG255, you will develop your own fractal pattern generation code using the Mandelbrot and Julia sets. For further



In this Final Course Project for PRG255, you will develop your own fractal pattern generation code using the Mandelbrot and Julia sets. For further background information and details, please make sure to watch this supplemental video recording as well as the recording of our Lab 7 session. Details already discussed in the pre- recorded video have been omitted from this document for conciseness. Your C program will generate one Mandelbrot and one Julia fractal pattern. Both will be written to disk in the Portable Gray Map (PGM) image format. Mandelbrot fractals are generated using an iterative complex function of the following form: Zn+1 = Z + C Zo = 0, where Z and C are complex numbers. These complex numbers can be thought of as points on a two-dimensional complex plane of size 2x2. The real and imaginary parts of these complex numbers represent the x and y coordinates of points on the complex plane. If our intended output image is projected onto the 22 complex plane, then point C represents an individual pixel on the image. As a result, for each individual pixel on the image, we can calculate successive values for Z based on the previous equations. We can also keep track of the length of Z as it gets updated at each iteration, and stop the iterative process when the square of the length of Z exceeds 4.0. The number of iterations required to breach this condition will then determine the color value associated with the pixel represented by the complex number C. The following pseudocode implements the steps required for generating a color value for each individual pixel on the intended output image of your program. This pseudocode implements the same logic described above. step_height 4.0/(double) height step_width 4.0/(double)width maxIter = 400 for (j = 0; j < height; j++) begin for (k = 0; k < width; k++) begin z = 0 + 01 c = (((double)j step_height) 2.0) + (((double)k step_width) 2.0)i color= fractal (z, c, maxIter) maxIter - color image[j][k] fprintf(image[j][k]) end fprintf(endline) end The two-level nested loop shown above iterates through every single pixel on the intended output image as it projects onto a 2x2 complex plane. For each pixel, it sets the value of complex number Z to zero and determines the corresponding complex number C by a simple projection of the image dimensions onto the complex plane. The color of this pixel is calculated by the fractal (z, c, maxIter) function. Note that the fractal(z, c, maxIter) function implements the same logic we used as part of Lab Modules 8 and 9. Once the color is determined, it is inverted by subtracting it from maxIter, which represents the color white in the PGM image. This value is now written to the output file as the color of the pixel represented by complex number C. The logic for generating the Julia fractal pattern is very similar to the one outlined above. The subtle difference is that the complex number C is set equal to a constant and remains unchanged. The complex number Z is used instead to iterate over all individual pixels of the image in the same way that C iterates over the image pixels in the Mandelbrot set. The constant value of C used will be equal to -0.8 +0.1561. Project Requirements Your implementation of the fractal pattern generation code must meet all the following requirements for full credit. 1. You must implement your code in a single C file named "main.c". 2. Your program must #include only the and libraries in your "main.c" program. 3. You must define and implement a typdef struct called Complex with two double members: real and imag. Your program must use this data type to store all complex numbers. 4. You must implement a function for carrying out any complex multiplication using the following interface: Complex complex_mult (Complex* a, Complex* b) 5. You must implement a function for carrying out any complex addition using the following interface: Complex complex_add(Complex* a, Complex* b) 6. You must implement a function for calculating the square value of the length of a complex number using the following interface: double len_square (Complex* a) 7. You must implement a function for calculating the color value of a given pixel using the same logic outlined in the Lab Modules 8 and 9. The function must have the following interface: int fractal (Complex* z, Complex* c, int maxIter) 8. Your program must output two separate images. One is to be named "mandelbrot.pgm", and the other "julia.pgm", displaying the Mandelbrot and Julia fractal patterns, respectively. 9. Your program must prompt the user to provide the width and height of the output images. The same width and height pair may be used for both output images. 10. You must use dynamic memory allocation to allocate a two-dimensional integer array called image based on the width and height for the purpose of storing the individual color values of all pixels in the images. This allocated array must be released prior to the end of your program.
Step by Step Solution
3.33 Rating (147 Votes )
There are 3 Steps involved in it
the color map isnt exactly perfect check if your instructor specifies any specifice kind of color ma... View full answer
Get step-by-step solutions from verified subject matter experts
