You are on page 1of 2

CO252: Computer Programming and Networking LAB 5: Mandelbrot Sets Introduction: According to Wikipedia A Mandelbrot set is mathematical set

of points whose boundary is a distinctive and easily recognizable two-dimensional fractal shape. We'll leave this definition out for now. Interestingly a Mandelbrot set's boundary includes smaller versions of the main shape it is essentially repeating itself but at a smaller size. Given image is a Mandelbrot set. Idea of this lab is generate and plot Mandelbrot sets.

Objective: . Introduce Java graphic libraries (at least on of them). Encourage referring the API manuals. Test your ability to read and understand Java code. Demonstrate the concepts of inheritance and super class. Demonstrate how a problem can be divided into smaller, more manageable tasks which are implemented as classes. Improve your coding ability. How it works: before get to coding we should get some idea about what a Mandelbrot set is. In mathematics Mandelbrot set is defined as the set of complex numbers C such that: Zn+1 = Zn2+C, starting with Z0 = 0 remains bounded when n reach infinity. In other words if for some C the above equation remains bounded for any number of iterations the that C is in the Mandelbrot set. Obviously we cannot find all Mandelbrot numbers because there are infinite number of them. So we only consider a region in the complex plane with some granularity (we need a granularity because between any two real numbers there is an infinite number of real numbers). Not all complex numbers belong to the Mandelbrot set. For some the above equation diverge slowly and for some rapidly. There is a mathematical proof which shows that if ABS(Zn) > 2 then that C is not in the Mandelbrot set. Generating the image: So we have a area (with some dimension) to plot the pattern. This area will contain pixels. For example the plot area may contain 800x800 pixels.

Furthermore, we need to select a region from the complex plane. Typically this region would be small compared to the plot area and will not start from (0,0). We call this region the complex region. To plot the image, we need to decide the colour of each pixel in the plot area. For this, we take a pixel, map it to a complex number in the complex region. Then we see if that complex number is in the Mandelbrot set or not. If it is we give it a colour, say black. If it is not in the Mandelbrot set then we assign the pixel a colour based on how fast the series diverged. For doing this you can simply count the number of iterations required to ABS(Z) to grow beyond 2. It the number of iterations are small it is diverging rapidly otherwise slowly. Programming: To implement this you are given a skeleton code. Your first task is to read and understand the code. One you have understood how it is done you can start the implementation. For the implementation you will need complex numbers and 2D points. You should implement them in separate classes as suggested by the skeleton code. You need a way of mapping a 2D point (from the plot area) to the complex plane. You know the dimensions of the plot area and the boundaries of the complex plane. Based on these information you should develop a method to do this mapping. Next comes the testing of a given complex number to see if it belongs to the Mandelbrot set. If it does belong then, Zn+1 = Zn2+ C should be bounded when n reach infinity. We cannot perform this computation till n reach infinity. So we define a upper limit ( maxit). We ABS(Zn) stays below 2 for that many iterations then we assume that C is in the Mandelbrot set. If not we assign the corresponding pixel a colour based on the rate at which the series diverged. Most of the code required for doing the plotting is already in the skeleton done. You are required to read and understand that code with the help of the Java online API reference. Submission: You should submit all the *.java files as a single zip file via Moodle before the deadline. As always you will be given marks for coding logic, correctness and neatness. Additionally you may submit your Mandelbrot plots via Moodle. We will select the best art and award 5 additional marks.