Use a Complex number class to draw Mandelbrot sets easily in C#

The example Draw a Mandelbrot set fractal in C# explains how to draw a Mandelbrot set by iterating the equation:

    Zn = Zn-12 + C

Where Zn and C are complex numbers. The program iterates this equation until the magnitude of Zn is at least 2 or the program performs a maximum number of iterations.

That example tracks the numbers' real and imaginary parts in separate variables. This example uses a Complex class to manage the complex numbers more easily and intuitively. The following code shows the program's main loop.

Complex Z = Z0;
Complex C = new Complex(ReaC, ImaC);
int clr = 1;
while ((clr < MaxIterations) &&
 (Z.MagnitudeSquared < MAX_MAG_SQUARED))
{
// Calculate Z(clr).
Z = Z * Z + C;
clr++;
}

See the code for details about how the Complex class works. The example Extend the complex number class to work with real numbers in C# describes some of the features of a class that is similar (although not exactly the same).

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.