0

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
    }
Matthew Miles
  • 727
  • 12
  • 26
  • You can try linearly interpolate the number of iterations from zoom ... If you want better performance use fractional escape (you need much less iterations for the same or better detail) and GLSL (massive paralelization performance boost) see [Can't find a way to color the Mandelbrot-set the way i'm aiming for](https://stackoverflow.com/a/56197067/2521214) on top of this you can exploit continual zoom see [What are the fastest algorithms for rendering the mandelbrot set?](https://stackoverflow.com/a/66719738/2521214) – Spektre Sep 18 '22 at 07:42
  • https://mrob.com/pub/muency/automaticdwelllimit.html – Adam Sep 19 '22 at 18:03
  • https://math.stackexchange.com/questions/2451036/maximum-iteration-for-mandelbrot-set – Adam Sep 19 '22 at 18:03

0 Answers0