I have a function which generates the values of the Mandelbrot Set within the range of [0-255]
. After calculating, I paint the result with the help of a pre-generated palette, that also has 256 values.
The calculation:
int MAX = 255;
private int calculateMandel(double positionX, double positionY) {
int valueOne = 0;
double complexReal = 0.0;
double complexImaginery = 0.0;
double complexRealSquare = 0.0;
double complexImaginerySquare = 0.0;
while (valueOne < MAX && complexRealSquare + complexImaginerySquare < 4.0) {
complexImaginery = 2.0 * complexReal * complexImaginery + positionY;
complexReal = complexRealSquare - complexImaginerySquare + positionX;
complexRealSquare = complexReal * complexReal;
complexImaginerySquare = complexImaginery * complexImaginery;
valueOne++;
}
return valueOne;
}
The result:
It is clearly a very bad rendering, because the levels can be seen, it is not smooth enough. How can I make my picture smoother? Like this: http://upload.wikimedia.org/wikipedia/commons/2/21/Mandel_zoom_00_mandelbrot_set.jpg
The way that the mandelbrot set works is that it tests how many iterations it takes to converge to a finite number, you detect this when
complexRealSquare + complexImaginerySquare < 4.0
The MAX value you have set to 255 limits the number of iterations it will take to converge and therefore has a sharp cut off giving you those lines you are seeing.To eliminate the lines you need to have more than 255 colors to map to. You can do this by painting with not just blue, but for instance start with red and move from red to blue.