Sierpinski Carpet

Sierpinski didn't just mess around with triangles, he also wrote 50 books (all of them flip-books of Sierpinski triangles, I assume), created a curve and released this: his signature edition Carpet design.

It takes a while to weave one properly, but what you waste on time you make up for on materials: it has an infinite edge and no area.

We're going to need a function for drawing a square.

And we're going to need a function for putting a square inside a larger area. It will build on the idea of a square, so it needs to import our square from above.

Now with that building block under our belt, we can build the carpet itself.

This will stop at a recursive depth of 4. If we took it to 5, it would take 8 times as long to build.

 

Logo + Turtle graphics via Papert.