aboutsummaryrefslogtreecommitdiff
path: root/src/mandelbrot.c
blob: 3c8ab98714d07450c47a9fd3ead611507bc4c9ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "mandel.h"

int mandelbrot(double ca, double cb, int iterations)
{
    double	zr = ca;
    double	zi = cb;
    double	zr_square;
    double	zi_square;
    int		n;

    for (n = 0; n < iterations; n++)
    {
        zi_square = zi * zi;
        zr_square = zr * zr;
        if (zr_square + zi_square > 4.0)
            return n;
        zi = 2.0 * zr * zi;
        zr = zr_square - zi_square;
        zi += cb;
        zr += ca;
    }
    return n;
}