29 lines
686 B
C++
29 lines
686 B
C++
|
|
#include <math.h> /* sqrt() */
|
|
#include <complex>
|
|
#include "FatouComputation.h"
|
|
using namespace std;
|
|
|
|
#define LEEWAY 0.001
|
|
#define ITERATIONS 100
|
|
#define CLOSE_ENOUGH(z, x, y) \
|
|
(fabs(creal(z) - (x)) < LEEWAY && fabs(cimag(z) - (y)) < LEEWAY)
|
|
|
|
static unsigned int colors[] = {0xFF0000, 0x00FF00, 0x0000FF};
|
|
|
|
unsigned int FatouComputation::compute(double x, double y)
|
|
{
|
|
complex<double> z(0.1);
|
|
complex<double> p(x, y);
|
|
|
|
for (int iter = 0; iter < ITERATIONS; iter++)
|
|
{
|
|
z = p * (complex<double>(1) - z) * z;
|
|
if (abs(z) > 2.0)
|
|
{
|
|
return colors[iter % (sizeof(colors)/sizeof(colors[0]))];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|