Skip to content

Instantly share code, notes, and snippets.

@kmcallister
Last active January 27, 2021 03:26
Show Gist options
  • Save kmcallister/c8d9975fd0733d9453ceec527db14bd0 to your computer and use it in GitHub Desktop.
Save kmcallister/c8d9975fd0733d9453ceec527db14bd0 to your computer and use it in GitHub Desktop.
module menger_sponge(n) {
if (n <= 0) {
cube(center=true);
} else {
for (x=[-1:1]) {
for (y=[-1:1]) {
for (z=[-1:1]) {
if (abs(x)+abs(y)+abs(z) >= 2) {
scale(1/3)
translate([x,y,z])
menger_sponge(n-1);
}
}
}
}
}
}
scale(30)
menger_sponge(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment