5

I've been working on drawing the Julia set using a distance estimator instead of the normalized iteration count. I usually use the code below and play around with the iteration count until I get a decent enough picture

double Mandelbrot::getJulia(double x, double y)
{
    complex<double> z(x, y);
    complex<double> c(-0.7269, 0.1889);

    double iterations = 0;

    while (iterations < MAX)
    {
        z = z * z + c;
        if (abs(z) > 2) {
            return iterations + 1.0 - log(log2(abs(z)));
            break;
        }
        iterations++;
    }
    return double(MAX);
}

I then call this for each point and draw to a bitmap;

    ZoomTool zt(WIDTH, HEIGHT);
    zt.add(Zoom(WIDTH / 2, HEIGHT / 2, 4.0 / WIDTH));
    for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
            pair<double, double> coords = zt.zoomIn(x, y);

            double iterations = Mandelbrot::getJulia(coords.first,
                coords.second);

            double ratio = iterations / Mandelbrot::MAX;
            double h = 0;
            double s= 0;
            double v = 0;

            if (ratio != 1)
            {
                h = 360.0*ratio;
                s = 1.0;
                v = 1.0;
            }

            HSV hsv(h, s,  v);
            RGB rgb(0, 0, 0);
            rgb = toRGB(hsv);

            bitmap.setPixel(x, y, rgb._r, rgb._g, rgb._b);
        }
    }

At 600 iterations, I get this;

decent Julia

Which is not great but better than what I get with the distance estimator which I am attempting to now use. I've implemented the distance estimator as below;

double Mandelbrot::getJulia(double x, double y)
{
    complex<double> z(x,y);
    complex<double> c(-0.7269, 0.1889);
    complex<double> dz = 0;

    double iterations = 0;

    while (iterations < MAX)
    {
        dz = 2.0 * dz * z + 1.0;
        z = z * z + c;

        if (abs(z) > 2)
        {
            return abs(z) * log(abs(z)) / abs(dz);
        }
        iterations++;
    }
    return Mandelbrot::MAX;
}

At 600 iterations, I get the following image crappy julia

Am I not normalizing the colors correctly? I'm guessing this is happening because I'm normalizing to 360.0 and doing a conversion from HSV to RGB. Since the distances are quite small, I get a very condensed distribution of colors.

Ozymandias
  • 839
  • 1
  • 8
  • 13

0 Answers0