The Fractal Applet's Java source code
The Fractal Applet was originally intended as an example of Object-Oriented Design for the University of Colorado.

This code may be compiled and run as an Application. This allows you to control the image size and the number of colors. I want to add a feature for saving images as JPGs or PNGs too, and that's prohibited in the Applet version for security reasons; the Applet must stay inside its "sandbox."

Here is example HTML for the Applet version:

< applet
  CODE = "fractal.Fractal.class"
  WIDTH = 800
  HEIGHT = 600 >
< PARAM NAME = "ImageWidth" VALUE = 470 >
< PARAM NAME = "ImageHeight" VALUE = 470 >
< PARAM NAME = "NumColors" VALUE = 512 >
< /applet >

Here is an example command line for the Application version:

java fractal.Fractal -w 800 -h 800 -c 1024

Note: for the Applet version, there are two size parameters that must be set in harmony with each other: the Applet's height and width plus DrawingCanvas' ImageHeight and ImageWidth. The -w and -h for the Application version's command line set the size of the image in pixels.

This code is an example of the Model View Controller design pattern, where class Fractal is the Controller, the Calculators and Drawings are the Model, and the ControlPanel and DrawingCanvas make up the View. The class Fractal is an example of the Mediator design pattern.

This program is multi-threaded. There are Java AWT threads that call into this code to paint() and notify of events such as mouse movements and button clicks. There are also calls that originate from the browser such as init() and stop(). And there is a thread to calculate each new Fractal. The code uses a single "monitor" object, the single instance of class Fractal, to control thread synchronization.

Note: a few minor features in the UI do not work across all browsers & JVMs. For example, on some browsers typing 'Enter' *always* calls doDraw()...

To download the Application version of Fractal, click HERE.

The Java source code is all contained in the following files:

fractal.ControlPanel.java
fractal.Drawing.java
fractal.DrawingCanvas.java
fractal.FastColorsCalculator.java
fractal.Fractal.java
fractal.FractalCalculator.java
fractal.HelpDrawing.java
fractal.JuliaCalculator.java
fractal.JuliaDrawing.java
fractal.MandelbrotCalculator.java
fractal.utils.ComplexPoint.java
fractal.utils.ComplexRectangle.java
fractal.utils.IntWrapper.java

Here are some UML models of Fractal's object-oriented design...