The Mandelbrot set and how to compute it is described in ``Computer Recreations,'' by A. K. Dewdney, Scientific American, Vol. 253, No. 2, pp. 16 - 24, Aug. 1985. You will understand the basic computation by reading pages 16 - 20.
You are to create an applet that displays the Mandelbrot set under the control of a user.
Initially, they will be (-2.0, -1.25i) and (0.5, 1.25i).
Each square is colored according to its iteration count (see the cited article). Use the colorMap method defined in the class MandelbrotSet to associate a point's count and iteration limit with a particular color.
When the user presses enter or return while in either of these TextFields, the applet displays the region, using the values of these TextFields to control the display.
After the second click, the applet, displays the region defined by these 2 new points in the complex plane.
_____________________________________________________________________________
public class Complex {
private double x;
private double y;
// Constructors
public Complex() {} // set point to 0,0
public Complex(Complex p) {}
public Complex(double x, double y) {}
// Get methods
public double getReal() {}
public double getImag() {}
// Set methods
public void setReal(double X) {}
public void setImag(double Y) {}
// [OPTIONAL] Assignment method
public void setComplex(Complex p) {}
// [OPTIONAL] Arithmetic methods
public Complex add(Complex p) {} // You can return void instead Complex
public Complex multiply(Complex p) {} // You can return void instead Complex
public double sizesq() {}
}
___________________________________________________
import java.awt.*;
public class MandelbrotSet {
private Complex lowerLeft;
private Complex upperRight;
// Constructor
public MandelbrotSet() {
lowerLeft = new Complex(-2, -1.25);
upperRight = new Complex(0.5, +1.25);
}
// Get methods
public Complex getLowerLeft() {}
public Complex getUpperRight() {}
// Set methods
public void setLowerLeft(Complex p) {}
public void setUpperRight(Complex p) {}
// Display method: Display region of complex plane as a resolution X resolution board
// of colored squares
public void displayMandelbrotSet(Graphics g, int limit, int resolution,
int pixels, int xOffset, int yOffset) {}
private Color colorMap(int count, int limit) {
return new Color((float) count/limit,
(float) (limit-count) / limit,
(float) ((count + limit/2) % limit) / limit
);
}
}
__________________________________________________________________________
import java.awt.*;
import java.applet.*;
public class Mandelbrot extends Applet {
// Applet constants
private final int APPSIZE = 500;
private final int PIXELS = 400; // PIXEL X PIXEL region to display Mandelbrot set
private final int XOFFSET = (APPSIZE - PIXELS)/2; // x coordinate of upper left pixel of display
private final int YOFFSET = 50; // y coordinate of upper left pixel of display
// Instance variables
private Complex lowerLeft;
private Complex upperRight;
private int limit; // iteration limit >= 1
private int resolution; // 1 <= resolution <= PIXELS
private MandelbrotSet s; // Mandelbrot set
// Utility variables
private Label limitLabel;
private Label resolutionLabel;
private TextField limitText; // Iteration limit
private TextField resolutionText; // Resolution
// add utility variables to taste
public void init() {}
public void paint(Graphics g) {
s.displayMandelbrotSet(g, limit, resolution, PIXELS, XOFFSET, YOFFSET);
}
public boolean action(Event event, Object o) {
// handle events in the limit and resolution text fields
// ...
return true;
}
public boolean mouseDown(Event event, int x, int y) {
// if click is outside display region, ignore
return false; // ignore mouse clicks outside of displayed region
// if click is inside display region, process request
return true;
}
}