*What Links Here?*

*Outbound Links*

# FlowSnake

The flowsnake, also known as the 'Peano-Gosper' curve is a rather dashing space-filling curve. There is also a demonstration of it on the space-filling curves page.

The following implementation uses 'mutual recursion' - i.e. two methods that call each other.

The flowsnake has the important property that it tiles the plane. And it does it in a somewhat sexier fashion than the Hilbert curve, which, in turn, is somewhat sexier than the Peano curve.

Here's a definition of a snowflake.

;export flowsnake to flowsnake :count :length ifelse :count = 0 [ fd :length ] [ flowsnake (:count-1) :length lt 60 flowsnake_r (:count-1) :length lt 120 flowsnake_r (:count-1) :length rt 60 flowsnake (:count-1) :length rt 120 flowsnake (:count-1) :length flowsnake (:count-1) :length rt 60 flowsnake_r (:count-1) :length lt 60 ] end to flowsnake_r :count :length ifelse :count = 0 [ fd :length ] [ rt 60 flowsnake (:count-1) :length lt 60 flowsnake_r (:count-1) :length flowsnake_r (:count-1) :length lt 120 flowsnake_r (:count-1) :length lt 60 flowsnake (:count-1) :length rt 120 flowsnake (:count-1) :length rt 60 flowsnake_r (:count-1) :length] end

Let's see it in action.

;import flowsnake flowsnake 3 9

What if we draw a bunch of flowsnakes one after the other? We get a flowsnake chain.

;import flowsnake repeat 3 [flowsnake 3 9]

What if we turn a little bit in between each flowsnake?

;import flowsnake ;export multi_flow to multi_flow :repeat :angle :count :length repeat :repeat [ flowsnake :count :length rt :angle ] end

We get a daisy chain of snowflakes.

How much we turn dictates how many snowflakes we get. They join up neatly.

;import multi_flow flowsnake 4 3 setxy 300 100 multi_flow 2 0 3 3 setxy 495 80 multi_flow 3 120 3 3 setxy 650 80 multi_flow 4 90 3 3 setxy 150 240 multi_flow 5 72 3 3 setxy 350 240 multi_flow 6 60 3 3 setxy 580 240 multi_flow 7 (360/7) 3 3 setxy 850 240 multi_flow 8 (45) 3 3 setxy 200 450 multi_flow 9 (40) 3 3 setxy 500 450 multi_flow 10 (36) 3 3

So if you're making a list from most to least sexy of the three space-filling curves I've covered, it would go Peano-Gosper, Hilbert, Peano.

There's something satisfying about that list: Peano-Gosper, Hilbert, Peano. If you created an L-system where "Peano" -> "Peano-Gosper, Hilbert, Peano", then after a few iterations you'd have:

Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano-Gosper, Hilbert, Peano.

And soon I think you'd find a way to demonstrate that this can be represented as a Sierpinski triangle. Sierpinski triangles are just like that. Always Popping Up When You Least Expect It.

# Overlapping Flowsnakes

Something interesting happens when we deliberately overlap a bunch of Flowsnakes.

This is the picture we get when we draw 6 flowsnakes, and turn left 60 degrees instead of turning right 60 degrees.

;import multi_flow multi_flow 6 300 3 12

That central part of that pattern would make for a very nifty and irregular tile motif in the bathroom of a retirement village for mathematics professors.

Or if we combine two 'multi flowsnakes' in a different configuration...

;import multi_flow multi_flow 3 120 3 12 rt 60 multi_flow 3 120 3 12 rt 30

Other combinations are possible.

;import multi_flow multi_flow 3 120 3 9 rt 120 multi_flow 3 120 3 9 rt 120 multi_flow 3 120 3 9 rt 30

Now. What if we didn't draw the lines of a flow snake. But instead draw the vertices.

Here's a variation I created, along those lines, that would make a pretty good T-shirt.

to dott circle 1 end to dot circle 3 end to flowsnake :count :length ifelse :count = 0 [ pu color [250 0 0] fd :length pd ] [ flowsnake (:count-1) :length dot lt 60 flowsnake_r (:count-1) :length dot lt 120 flowsnake_r (:count-1) :length dot rt 60 flowsnake (:count-1) :length dot rt 120 flowsnake (:count-1) :length dot flowsnake (:count-1) :length dot rt 60 flowsnake_r (:count-1) :length dot lt 60 ] end to flowsnake_r :count :length ifelse :count = 0 [ pu color [0 0 250] fd :length pd ] [ rt 60 flowsnake (:count-1) :length dott lt 60 flowsnake_r (:count-1) :length dott flowsnake_r (:count-1) :length dott lt 120 flowsnake_r (:count-1) :length dott lt 60 flowsnake (:count-1) :length dott rt 120 flowsnake (:count-1) :length dott rt 60 flowsnake_r (:count-1) :length dott ] end flowsnake 4 9

For example: