I am a fairly new to programming in C++, and for the sake of improving I am trying to make a mandelbrot set consol application. I have gotten it to work almost perfectly: The image generates, I can zoom in/out, and move around very easily. The problem I have, though, is when I start zooming on into the edges of the image, the edges will start to get “cut off”
Image zoomed out:

Image zoomed in a little – as you can see half the last “circle” has been chopped off:

Lastly, zoomed in one for time, the whole last “circle” has been completely chopped off:

If I kept zooming in, then the edges of the bigger circle would start to be chopped, too.
I do not understand completely why this is happening, but my guess would be my zooming method is somehow to blame.
Here is the source code for the algorithm calculation function (where I’m guessing the error is):
int fractalCalc(double x0, double y0, double zoom)
{
double x = 0;
double y = 0;
int iteration = 0;
int max_iteration = 1000; //1000
double xtemp;
while (x*x + y*y < 2*2 && iteration < max_iteration) //x*x + y*y < 2*2 && iteration < max_iteration
{
xtemp = x*x - y*y + x0;
y = 2*x*y + y0;
y /= zoom;
x = xtemp;
x /= zoom;
iteration++;
}
return iteration;
}
For the whole source code, go to (because my prediction is most likely wrong): http://pastebin.com/WhbS0WYE
Any suggestions and/or assistance welcome. Thank you in advance!
I haven’t done the maths closely, but I suspect it’s due to the way you’re handling the zoom. I would suggest not doing it in the code which handles the actual Mandelbrot depth calculation.
Instead, use the zoom to pick a “viewport” from which to pick samples. Work out which co-ordinates you want to sample, and then write your
fractalCalcfunction to just compute the depth of a specific point. That function doesn’t need to know anything about what you’re displaying.Aside from anything else, this separation of concerns (viewport vs fractal part) will make it easier to reason about and debug. It will also mean you’re doing fewer calculations per iteration, which should lead to fewer floating point inaccuracies.