mandelPoint.c

C

Public Domain

Determine how many iterations of the Mandelbrot function it takes a point to escape

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
int mandelPoint(double a, double b, int max) {
/* Returns the number of turns it takes the point a+bi to escape; returns -1 if the
 * point does not escape within `max' iterations */
 if (a*a + b*b > 4.0) return 0;
 double x=a, y=b;
 for (int i=0; i<max; i++) {
  double xTmp = x;
  x = x*x - y*y + a;
  y = 2 * xTmp * y + b;
  if (x*x + y*y > 4.0) return i+1;
 }
 return -1;
}