Skip to content

Instantly share code, notes, and snippets.

@mechamug
Created February 26, 2020 17:15
Show Gist options
  • Save mechamug/d1415f57e673e935976cc8ef399cf4c2 to your computer and use it in GitHub Desktop.
Save mechamug/d1415f57e673e935976cc8ef399cf4c2 to your computer and use it in GitHub Desktop.
function countIterations(x, y) {
var count = 0;
var t = x;
x=-y;
y=t;
var zx = x;
var zy = y;
var n = 100;
var p = 200;
while (count < maxIterations && zx*zx + zy*zy < 20) {
if (0==(count+1)%n) {
x += zx*count/p;
y += zy*count/p;
n--;
p++;
}
var new_zx = zx*zx - zy*zy + x;
zy = 2*zx*zy + y;
zx = new_zx;
count++;
}
return count < maxIterations ? count : Math.floor((Math.atan(zy/zx)+Math.PI/2)/Math.PI*count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment