Part I

Part II: Setting Up the Project

The first step is to set up the project inside Visual Studio. This is not complex, you only need to create a new solution with a Windows Form project. I named it FractalGenerator. In order to use the main Form as a MDI container you have to enable the IsMDIContainer property:

I am not going to explain the .Net details of my project: you can either build your own main window or look at my code. The only important thing is that the main window offers a way to select one of the available Fractals, and shows the FractalView form that I am going to describe.

In order to have a list of the available algorithms I use the following code in the main form contructor:

private List<IGenerator> generators;
private
Options preferences;

public FractalGenerator()
{
    this.generators = new List<IGenerator>();
    this
.generators.Add(new Mandelbrot());
    this
.generators.Add(new MandelbrotEscapeTime());
    this
.generators.Add(new MandelbrotBW());
    this
.generators.Add(new JuliaEscapeTime());
    this
.generators.Add(new Newton3());
    this
.generators.Add(new Newton3BW());

    this.preferences = new Options(400, 400, 2, 4, 5);

    InitializeComponent();
}

IGenerator is an interface that each Fractal class must implement. Both the interface and the classes will be described later. Just notice that I keep a list of the implemented Fractals.
The Options structure simply holds the following values:

-Width and Height of the output image.
-Supersampling level to antialias the image.
-Number of threads to use to generate the image.
-Number of images to keep in memory while zooming into the Fractal.

I use a top menu to show the available algorithms and to display an Options form. The following code creates and shows the FractalView form for the selected Fractal:

void generator_Click(object sender, EventArgs e)
{
    IGenerator generator = ((IGenerator)((ToolStripItem)sender).Tag).CreateGenerator();
    FractalView
newForm = new FractalView(generator.GetName(), generator, this.preferences);
    newForm.MdiParent =
this;
    newForm.Show();
}

When the user selects a menu entry, the generator_Click() event handler is invoked. I use the Tag property of the ToolStripItem control to keep a reference to its associated Fractal generator. Through a factory method defined by the IGenerator interface I create an instance of the specific Fractal an pass it to the FractalView contructor (described later). Finally I add the form to the main window.

As you see, there is not much to say about the main form, as most of the work is performed by the FractalView and IGenerator classes.