Project 1.A: Mandelbrot Set

Click on image to see Mandelbrot fly-through

This is the first installment of your course project. There are several interesting facets of the project as a whole that may make it interesting for you. Do not wait until the last minute to work on project deliverables. You will suffer in many ways if you do. This is an individual project. As always, I encourage you to talk to your peers or to me and to ask questions. But the code you submit must be your own code.

This project, once implemented, will render the Mandelbrot Set for a given region of the complex plane. For your second installment, your program will generate an image similar to the one at the right and allow the user to zoom in and out from specific points of the image; for the first installment, we will start more modestly. We'll go over the math in the class. You are always welcome to ask questions during office hours or other times by arrangement. You can learn much more than you need for the project at the Wikipedia site for the Mandelbrot Set. The Wikipedia page has pseudocode that takes you most of the way.


Draw the Mandelbrot Set.

  1. Getting started. Create a class, Mandelbrot1, that extends Frame and display the window in which you will eventually draw the Mandelbrot image. Your window should be 600x400 pixels at this point.

  2. Determine set membership. The key to the Mandelbrot set is determining, for each point on the complex plane, whether or not the point is a member of the set. A complex point, c, is said to be in the set if a number of iterations of the equation:

    	zt+1 = zt2 + c
    with z0 starting at the origin, stays within a fixed radius of the origin. For a given complex point, c, if one iterates this equation a sufficient number of times without the point zt escaping from the origin by more than 2, then the point may be considered for our purposes to be be in the set. To start, we will use 100 as the sufficient number of iterations.

    Write a function, inMandelbrot(Point2D.Double), that consumes a java.awt.geom.Point2D.Double and returns a boolean value. The truth value signifies whether the given point belongs to the Mandelbrot set (when true) or not (when false). Note, the Point2D.Double is a point on the complex plane but corresponds to a pixel of your canvas that might be represented as a Point or a Point2D. If you follow the pseudocode found at the Wikipedia site you should be fine. But spend some time trying to understand the pseudocode -- we'll be going over it in class.

  3. Display the image. Display the points of the complex plane in the range [-2,1] to [1,-1]. Naturally, you'll need to map this region of the plane onto your canvas with upper-left corner [0,0] (actually, the appropriate pixel coordinates should allow for Insets) and a particular WIDTH and HEIGHT. As a recommendation, write a method, mapCanvasToComplex, that takes as argument two ints in the canvas coordinate system and returns a Point2D.Double representing the corresponding point in the complex plane. You should code this correspondence between points on the complex plane and pixels on the canvas in a way that will allow maximal generality because next week you will be zooming in and out while recentering the portion of the plane that is visible on the canvas. At this stage, the resulting image should have two colors. Points in the Mandelbrot set should be colored black, and other points should be another color, say red.

  4. Color the image. To achieve more attractive images, you will now color points that are not in the Mandelbrot Set using a variety of colors. A point that escapes from the circle of radius 2 surrounding the origin will do so after some number of iterations of the equation above. This number will (at this stage) be between 1 and 99 inclusive. Map the number of iterations prior to escape onto a unique color and paint such points with that color.

Submission instructions:

Do not forget to use the javadoc constructs for your documentation and include the html file produced by the javadoc tool in your final submission. Make sure that you create a folder named with your Westmont email name followed by “P1A”. For example, someone with email address “cjones” would create a folder called “cjonesP1A”. Make sure that inside that folder you have: java source files and html documentation files resulting from javadoc. Finally, either tar or zip the folder so that when we extract it, the folder “<emailname>P1A” will be created. Submit the packaged file for project 1.A on Eureka.