Skip to content

Instantly share code, notes, and snippets.

@callandekeijzer
Last active April 4, 2018 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callandekeijzer/aa70451acfcf2d97ec0e18155a1d8ed7 to your computer and use it in GitHub Desktop.
Save callandekeijzer/aa70451acfcf2d97ec0e18155a1d8ed7 to your computer and use it in GitHub Desktop.
3D mandelbulb generated by VEX code in houdini
//---Functions---
/*
r = sqrt(x*x + y*y + z*z )
theta = atan2(sqrt(x*x + y*y) , z)
phi = atan2(y,x)
newx = r^n * sin(theta*n) * cos(phi*n)
newy = r^n * sin(theta*n) * sin(phi*n)
newz = r^n * cos(theta*n)
*/
function int Mandel(float x0, y0, z0; int imax){
float x, y, z, xnew, ynew, znew, n=ch("n"), r, theta, phi;
int i;
x = x0;
y = y0;
z = z0;
for(i=0; i < imax; i++){
//xnew = x*x - y*y + x0;
//ynew = 2 * x * y + y0;
r = sqrt(x*x + y*y + z*z );
theta = atan2(sqrt(x*x + y*y) , z);
phi = atan2(y,x);
xnew = pow(r, n) * sin(theta*n) * cos(phi*n) + x0;
ynew = pow(r, n) * sin(theta*n) * sin(phi*n) + y0;
znew = pow(r, n) * cos(theta*n) + z0;
if(xnew*xnew + ynew*ynew > 8){
return(i);
}
x = xnew;
y = ynew;
z = znew;
}
return(imax);
}
//--- Main ---
int maxiter = 60;
if(Mandel(@P.x, @P.y, @P.z, maxiter) < maxiter){
@density = 0.0;
}
else{
@density = 1.0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment