Using recursion, it’s very easy to generate in LOGO some special curves called fractals in mathematics.
Here are the first steps to create the Van Koch broken line:
Between two steps:
What is important: Let’s have a look at step 2, we can see that the broken lines contains four identical motifs
corresponding to precedent step with a 3 lesser size. Here we have found the recursive structure of the
fractal.
Let’s call Ln,ℓ the motif of size ℓ, corresponding to step n.
To draw this motif:
With LOGO, it’s very easy to write:
# :l motif size # :p step to line :l :p if :p=0 [fd :l] [ line :l/3 :p-1 lt 60 line :l/3 :p-1 rt 120 line :l/3 :p-1 lt 60 line :l/3 :p-1 ] end |
If we draw an equilateral triangle with three Van Koch lines, we obtain a beautiful Van Koch snowflake.
# :l side length to snowflake :l :p repeat 3[line :l :p rt 120] end |
Then run: snowflake 200 6