How many iterations of the Mandelbrot set for an accurate picture at a certain zoom?

Viewed 24

I have implemented the mandelbrot set algorithm in Java which I am using to make an animation of zooming into the set. My problem is that the algorithm is performing very slowly since I have it set such that the maximum number of iterations is high (1000) so that clarity will be preserved when zooming in closely. However, when on a more zoomed-out picture, only around 100 iterations are required to have an accurate picture.

The Mandelbrot set

My question is: is there some function f(x) such that for x screen width, clarity will be acceptable? (This only needs to be approximate since the definition of "clear" isn't itself very clear, but the trendline should follow the rate of increase of accuracy which follows the set itself)

Here is my current implementation of the algorithm:

    private double[] target = {-1.256640565451168862869, -0.382386428889165027247};

    // Returns an integer RGB value (0xRRGGBB) representing the colour which should be drawn at a certain position on the screen
    private int getMandleRGB(int x, int y, int w, int h) {
        Complex c = new Complex();
        c.r = lerp(lerp(-2, target[0], 1-zoom), lerp(1, target[0], 1-zoom), x/(double) w);
        c.i = lerp(lerp(-1.5, target[1], 1-zoom), lerp(1.5, target[1], 1-zoom), y/(double) h);
        Complex z = new Complex();
        z.r = c.r;
        z.i = c.i;

        int i = 0;
        for (i = 0; i < 1000; i++) {
            z = Complex.add(Complex.multiply(z, z), c);

            if (z.i*z.i+z.r*z.r > 4) {
                double t = Math.log(i)/Math.log(1000d);
                return (int) lerp((gradient[0] & 0xff0000) >> 16,
                                  (gradient[1] & 0xff0000) >> 16, t)*0x10000
                     + (int) lerp((gradient[0] & 0xff00) >> 8,
                                  (gradient[1] & 0xff00) >> 8, t)*0x100
                     + (int) lerp((gradient[0] & 0xff),
                                  (gradient[1] & 0xff), t);
            }
        }

        return 0x000000; // black
    }
0 Answers
Related