Patterns Inside Patterns
Real recursion is a block that calls itself. Star Blocks keeps you one step away from that, and honestly that is a good place to learn the idea: a unit makes a ring, and rings make a bigger ring. The same rule at three sizes gives you a pattern that looks far cleverer than the code.
π‘ The idea
A block built from a block built from a block: self-similar patterns from three tiny definitions.
- Self-similar means the small parts look like the whole.
- Each level uses the level below it as if it were a single command.
- Every level must finish where it started, or the levels drift apart.
- This is the idea behind recursion, written out as separate named levels.
- Three short blocks can produce a picture that would take hundreds of lines by hand.
π Words to know
- self-similar
- the small parts look like the whole
- recursion
- a definition that uses itself
- level
- one layer of a pattern built on the layer below
π Watch this
Squares make a rosette, and six rosettes make a ring: one idea used at three sizes.
to unit repeat 4 [ forward 20 right 90 ] end to ring repeat 6 [ unit right 60 ] end to garden repeat 6 [ ring forward 60 right 60 ] end garden
βοΈ Your turn
- Run it, then comment out the last line with # and confirm nothing draws.
- Change only the unit, to repeat 4 [ forward 30 right 90 ], and see all three levels change.
- Change ring to repeat 8 [ unit right 45 ].
- Change garden to repeat 3 [ ring forward 90 right 120 ].
- Explain why every level has to end where it began.
π― Challenge: Rebuild all three levels with a triangle as the unit. Predict how the whole picture will change before you run it.
Show me one answer
to unit repeat 3 [ forward 25 right 120 ] end to ring repeat 8 [ unit right 45 ] end to garden repeat 4 [ ring forward 70 right 90 ] end garden
Your program