// menger sponge // scruss 2016-06-18 // after cortex's (josh millard) wall thingy // outputs a 2D section diagonally through a level 3 Menger sponge s=270; module x_sierpinski() { linear_extrude(height=s) difference() { square(s); union() { for (x=[1:1]) { for (y=[1:1]) { translate([s*(1+3*(x-1))/3, s*(1+3*(y-1))/3])color("blue")square(s/3); } } for (x=[1:3]) { for (y=[1:3]) { translate([s*(1+3*(x-1))/9, s*(1+3*(y-1))/9])color("green")square(s/9); } } for (x=[1:9]) { for (y=[1:9]) { translate([s*(1+3*(x-1))/27, s*(1+3*(y-1))/27])color("red")square(s/27); } } } } } // if you remove the outer projection clause you get a nice 3D figure projection(cut = true) { rotate([-1*atan2(1,sqrt(2)),0,0])rotate([0,-45,0]) translate([-s/2, -s/2, -s/2]) intersection() { x_sierpinski(); translate([0,0,s]) rotate([-90,0,0]) x_sierpinski(); translate([s,0,0]) rotate([0,-90,0]) x_sierpinski(); } }