1 #ifndef FRACTAL_MATH_H_
2 #define FRACTAL_MATH_H_
6 #include "CalibreurF.h"
7 #include "ColorTools.h"
13 * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.
17 : n(n
), calibreur(IntervalF(1, n
), IntervalF(0, 1))
22 virtual ~FractalMath() {}
30 void colorXY(uchar4
* ptrColor
, float x
, float y
) const
34 this->initZ(z_r
, z_i
, x
, y
);
41 nextZ(z_r
, z_i
, x
, y
);
43 if (isDivergent(z_r
, z_i
))
55 float s
= static_cast<float>(i
);
56 this->calibreur
.calibrer(s
);
57 ColorTools::HSB_TO_RVB(s
, ptrColor
);
63 static bool isDivergent(float a
, float b
)
65 return pow(a
, 2) + pow(b
, 2) > 4;
69 virtual void initZ(float& z_r
, float& z_i
, float x
, float y
) const = 0;
72 virtual void nextZ(float& z_r
, float& z_i
, float x
, float y
) const = 0;
79 class FractalMandelbrotMath
: public FractalMath
83 * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.
86 FractalMandelbrotMath(int n
)
93 void initZ(float& z_r
, float& z_i
, float, float) const
100 void nextZ(float& z_r
, float& z_i
, float x
, float y
) const
103 float z_r_tmp
= pow(z_r
, 2) - pow(z_i
, 2);
104 z_i
= 2 * z_r
* z_i
+ y
;
109 class FractalJuliaMath
: public FractalMath
113 * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.
116 FractalJuliaMath(int n
, float c_r
, float c_i
)
117 : FractalMath(n
), c_r(c_r
), c_i(c_i
)
123 void initZ(float& z_r
, float& z_i
, float x
, float y
) const
130 void nextZ(float& z_r
, float& z_i
, float, float) const
133 float z_r_tmp
= pow(z_r
, 2) - pow(z_i
, 2);
134 z_i
= 2 * z_r
* z_i
+ this->c_i
;
135 z_r
= z_r_tmp
+ this->c_r
;