# 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.

; export square to square :length repeat 4 [ fd :length rt 90 ] end

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.

; import square ; export fsquare to fsquare :length pu fd :length rt 90 fd :length lt 90 pd square :length pu lt 90 fd :length lt 90 fd :length rt 180 pd end

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

; import fsquare ; export carpet to carpet :length :depth fsquare :length if :depth > 0 [ ;fsquare :length repeat 4 [ repeat 2 [ carpet :length/3 (:depth - 1) pu fd :length pd ] pu fd :length pd rt 90 ] ] end

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

;import carpet square 600 carpet 200 4