I am trying to visualize the Mandelbrot set with OpenGL and have discovered very strange behavior when it comes to smooth coloring.
Suppose that for the current complex value, the Calgorithm slipped away after niterations when Zit was proved that it is greater than 2.
I programmed the color part as follows:
if(n==maxIterations){
color=0.0; //0.0 is black in OpenGL when put to each channel of RGB
//Points in M-brot set are colored black.
} else {
color = (n + 1 - log(log(abs(Z)))/log(2.0) )/maxIterations;
//continuous coloring algorithm, color is between 0.0 and 1.0
//Points outside M-brot set are colored depending of their absolute value,
//from brightest near the edge of set to darkest far away from set.
}
glColor3f(color ,color ,color );
//OpenGL-command for making RGB-color from three channel values.
The problem is that it just doesn't work. Some smoothing is noteworthy, but not perfect.
But when I add two additional iterations (just found this somewhere without explanation)
Z=Z*Z+C;
n++;
in the "else" branch before calculating the color, the picture is absolutely, gracefully smooth.
Why is this happening? Why do we need to add additional iterations to the color part after checking the point to be set?