//http://local.wasp.uwa.edu.au/%7Epbourke/fractals/gasket/ // Menger Sponge #include "colors.inc" camera { location <2, 2, -5> look_at <0, 0, 0> } light_source { <100, 100, -10> color White} light_source { <-10, 1, -10> color .5*White} light_source { <0, 0, 0> color .5*White} #macro sponge(s, base_center, recursion_depth) #if (recursion_depth > 0) union { sponge(s / 3, base_center + 2*s/3*(x+y+z), recursion_depth - 1) sponge(s / 3, base_center - 2*s/3*(x+y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x+y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x-y-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x-y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x+y-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x+y-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x-y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x-y), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x+y), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x+y), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x-y), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(y-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-y-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-y+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x+z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(x-z), recursion_depth - 1) sponge(s / 3, base_center + 2*s/3*(-x+z), recursion_depth - 1) } #else difference{ box {s*< 1,1,1>, s*<-1,-1,-1>} box {< s/3, s/3, 1.1*s>, <-s/3, -s/3, -1.1*s>} box {< 1.1*s, s/3, s/3>, <- 1.1*s, -s/3, -s/3>} box {< s/3, 1.1*s, s/3>, <-s/3, - 1.1*s, -s/3>} //scale s*1.0 translate base_center pigment { rgb <1,0,0>} finish { ambient .2 diffuse .6 } } #end #end sponge(1,<0,0,0>,3) // An infinite planar surface // plane {, D } where: A*x + B*y + C*z = D plane { y, // unit surface normal, vector points "away from surface" -1.5 // distance from the origin in the direction of the surface normal pigment { rgb <.3,.3,1>} }