mandelbrot/mandelbrot.c
int mandelbrot(double ca, double cb, int n)
{
    /* We want to iterate the following function
    and find out if it diverges or is bounded

    f(z) = z^2 + c
    z starts at 0
    where c is a number in the complex plane
    and z is the previous iteration result

    z is complex number 
    which stores the result of the previous iteration */
    double za = 0.0;
    double zb = 0.0;
    
    int i = 0;
    while (i < n)
    {
        /* z^2 = (a + bi)^2
               = (a + bi) * (a + bi)
               = (a^2 + 2abi - b^2) */
        double real = (za * za - zb * zb) + ca;
        double imag = (2.0 * za * zb) + cb;

        /* save result for next iteration */
        za = real;
        zb = imag;

        /* if we have exceeded the bounds we are done */
        if (za * za + zb * zb > 2.0) break; 
        ++i;
    }

    return i;
}
/* the input c is a complex coordinate in the plane
ca is the real part. cb is imaginary.
n is the number of iterations */
the input c is a complex coordinate in the plane
ca is the real part. cb is imaginary.
n is the number of iterations
the input c is a complex coordinate in the plane ca is the real part . cb is imaginary . n is the number of iterations
int mandelbrot(double ca, double cb, int n)
{
    double za = 0.0;
    double zb = 0.0;
    int i = 0;
    while (i < n)
    {
        double real = (za * za - zb * zb) + ca;
        double imag = (2.0 * za * zb) + cb;
        za = real;
        zb = imag;
        if (za * za + zb * zb > 2.0) break; 
        ++i;
    }
    return i;
}
int mandelbrot ( double ca , double cb , int n ) { double za = 0.0 ; double zb = 0.0 ; int i = 0 ; while ( i < n ) { double real = ( za * za - zb * zb ) + ca ; double imag = ( 2.0 * za * zb ) + cb ; za = real ; zb = imag ; if ( za * za + zb * zb > 2.0 ) break ; ++ i ; } return i ; }
the input c is a complex coordinate in the plane
ca is the real part.
the input c is a complex coordinate in the plane ca is the real part .
/* We want to iterate the following function
    and find out if it diverges or is bounded

    f(z) = z^2 + c
    z starts at 0
    where c is a number in the complex plane
    and z is the previous iteration result

    z is complex number 
    which stores the result of the previous iteration */ /* z^2 = (a + bi)^2
               = (a + bi) * (a + bi)
               = (a^2 + 2abi - b^2) */ /* save result for next iteration */ /* if we have exceeded the bounds we are done */