0

I've coded a basic Mandelbrot explorer in C#, but I have those horrible bands of color, and it's all greyscale.

I have the equation for smooth coloring: mu = N + 1 - log (log |Z(N)|) / log 2

Where N is the escape count, and |Z(N)| is the modulus of the complex number after the value has escaped, it's this value which I'm unsure of.

My code is based off the pseudo code given on the wikipedia page: http://en.wikipedia.org/wiki/Mandelbrot_set#For_programmers

The complex number is represented by the real values x and y, using this method, how would I calculate the value of |Z(N)| ?

Sam Kennedy
  • 95
  • 1
  • 7

1 Answers1

1

|Z(N)| means the distance to the origin, so you can calculate it via sqrt(x*x + y*y).

If you run into an error with the logarithm: Check the iterations before. If it's part of the Mandelbrot set (iteration = max_iteration), the first logarithm will result 0 and the second will raise an error. So just add this snippet instead of your old return code. .

        if (i < iterations)
        {
            return i + 1 - Math.Log(Math.Log(Math.Sqrt(x * x + y * y))) / Math.Log(2);
        }
        return i;

Later, you should divide i by the max_iterations and multiply it with 255. This will give you a nice rgb-value.

michaeln
  • 1,032
  • 17
  • 33