Pregunta

I've been bashing my head against this all day. I feel like this really should work! No matter what I do to tweak this it outputs a single dot. Any help will be very much appreciated!

double x_init, y_init;  //These will be the real and imaginary aspects of C 
double x_temp, y_temp;  //We gotta hold values while we update the new x, y since they are based recursively on previous values;
double arg; // This will be our square root test



for (double y = - 1.6; y < 1.6; y += .002)
{
    for (double x = -1.5; x < 0.6; x += .004)
    {
        x_init = x;
        y_init = y;

        int iter = 0;
        arg = 0;
        while(iter < 50 && arg < 2)
        {
            x_temp = x;
            y_temp = y;
            x = (x_temp * x_temp) - (y_temp * y_temp) + x_init;
            y = 2 * x_temp * y_temp + y_init;
            arg = sqrt(x*x + y*y);
            iter++;
        }
        if (iter > 40)
        {
            drawBlack(x_init, y_init);

        }


    }
}
¿Fue útil?

Solución

There are 2 problems:

1) You've set the maximum iterations to 50, but then you use a max iterations of 40 to determine whether to draw black.

2) You're using the x and y coordinates of the equation to draw. You need to keep a separate x and y pixel coordinate at which you are drawing.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top