}
function mandelbrotValue (aC, aIterMax) {
- var Z = new complex(0.0, 0.0);
+ /* XXX: this would be nice code but it looks like JS objects are too heavy for this.
+ let Z = new complex(0.0, 0.0);
for (var iter = 0; iter < aIterMax; iter++) {
Z = Z.square().add(aC);
if (Z.r * Z.r + Z.i * Z.i > 256) { break; }
}
+ */
+
+ // highly optimized code for fast calculation
+ let Cr = aC.r, Ci = aC.i;
+ let Zr = 0.0, Zi = 0.0;
+ let Zr2 = Zr * Zr, Zi2 = Zi * Zi;
+ for (var iter = 0; iter < aIterMax; iter++) {
+ Zi = 2 * Zr * Zi + Ci;
+ Zr = Zr2 - Zi2 + Cr;
+
+ Zr2 = Zr * Zr; Zi2 = Zi * Zi;
+ if (Zr2 + Zi2 > 256) { break; }
+ }
return iter;
}