Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Created April 27, 2013 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/5473009 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/5473009 to your computer and use it in GitHub Desktop.
fractalFunctions = {
'mandlebrot': function(cx, cy, maxIter) {
var iter, xn, yn, x = 0, y = 0;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn = x*x - y*y + cx;
yn = (x*y)*2 + cy;
x = xn;
y = yn;
}
return iter;
},
'burningShip': function(cx, cy, maxIter) {
var iter, xn, yn, x = 0, y = 0;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn = x*x - y*y - cx;
yn = 2*Math.abs(x*y) + cy;
x = xn;
y = yn;
}
return iter;
},
'multibrot': function(cx, cy, maxIter, cr) {
var iter, xn, yn, x = 0, y = 0,n1,n2,n3;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
n3=(x*x+y*y);
if(!n3){
x=cx;
y=cy;
continue;
}
n1=Math.pow(n3,(cr>>1));
n2=cr*Math.atan2(y,x);
xn=n1*Math.cos(n2) + cx;
yn=n1*Math.sin(n2) + cy;
x = xn;
y = yn;
}
return iter;
},
'multibrot3': function(cx, cy, maxIter) {
var iter, xn, yn, x = 0, y = 0;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn=Math.pow(x,3)-3*x*Math.pow(y,2) + cx;
yn=3*Math.pow(x,2)*y-Math.pow(y,3) + cy;
x = xn;
y = yn;
}
return iter;
},
'multibrot5': function(cx, cy, maxIter) {
var iter, xn, yn, x = 0, y = 0;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn=Math.pow(x,5)-(10*Math.pow(x,3)*Math.pow(y,2))+(5*x*Math.pow(y,4)) + cx;
yn=(5*Math.pow(x,4)*y)-(10*x*x*Math.pow(y,3))+Math.pow(y,5) + cy;
x = xn;
y = yn;
}
return iter;
},
'tricorn': function(cx, cy, maxIter) {
var iter, xn, yn, x = 0, y = 0;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn = x*x - y*y - cx;
yn =(x+x)*(-y) + cy;
x = xn;
y = yn;
}
return iter;
},
'julia': function(cx, cy, maxIter, cr, ci) {
var iter, xn, yn, x = cx, y = cy;
for (iter = 0; x*x + y*y < 4&&iter < maxIter; iter++) {
xn = x*x - y*y + cr;
yn = (x*y)*2 + ci;
x = xn;
y = yn;
}
return iter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment