This first example helps to understand what is a Lindenmayer system but we can’t see for now the rapport with our
turtle and LOGO..
Here it comes interesting: every word we built before has no meaning. We’re going to define for each letter of the
sequence an action to execute with the turtle, and draw with this method 2D or 3D drawing.
For example, if α = 90 with a unit step of 10 turtle steps, we have:
|
First iterations:
XLOGOProgram:
to snowflake :p globalmake "unit 300/power 3 :p-1 repeat 3 [f :p-1 right 120] end to f :p if :p=0 [forward :unit stop] f :p-1 left 60 f :p-1 right 120 f :p-1 left 60 f :p-1 end |
Here are the first representations using α = 90, we adjust the unit step for the figure has a constant size.
Then it is very easy to create a Logo program to generate these drawings:
# p represent the order to koch :p # Between two iteration, the unit step is divided by 4 # The final figure will have a maximal size of 600x600 globalmake "unit 300/power 4 :p-1 repeat 3 [f :p-1 left 90] f :p-1 end # Rewriting rules to f :p if :p=0 [forward :unit stop] f :p-1 left 90 f :p-1 right 90 f :p-1 right 90 f :p-1 f :p-1 left 90 f :p-1 left 90 f :p-1 right 90 f :p-1 end |
A → A + B+ |
B →−A − B |
to a :p if :p=0 [forward :unit stop] a :p-1 left 90 b :p-1 left 90 end to b :p if :p=0 [forward :unit stop] right 90 a :p-1 right 90 b :p-1 end to dragon :p globalmake "unit 300/8/ :p a :p end |
|
A → B − F + CFC + F − D&F^D − F + &&CFC + F + B∕∕ |
B → A&F^CFB^F^D^^ − F − D^|F^B|FC^F^A∕∕ |
C →|D^|F^B − F + C^F^A&&FA&F^C + F + B^F^D∕∕ |
D →|CFB − F + B|FA&F^A&&FB − F + B|FC∕∕ |
to hilbert :p clearscreen 3d globalmake "unit 400/power 2 :p linestart setpenwidth :unit/2 a :p lineend view3d end to a :p if :p=0 [stop] b :p-1 right 90 forward :unit left 90 c :p-1 forward :unit c :p-1 left 90 forward :unit right 90 d :p-1 downpitch 90 forward :unit uppitch 90 d :p-1 right 90 forward :unit left 90 downpitch 180 c :p-1 forward :unit c :p-1 left 90 forward :unit left 90 b :p-1 rightroll 180 end to b :p if :p=0 [stop] a :p-1 downpitch 90 forward :unit uppitch 90 c :p-1 forward :unit b :p-1 uppitch 90 forward :unit uppitch 90 d :p-1 uppitch 180 right 90 forward :unit right 90 d :p-1 uppitch 90 right 180 forward :unit uppitch 90 b :p-1 right 180 forward :unit c :p-1 uppitch 90 forward :unit uppitch 90 a :p-1 rightroll 180 end to c :p if :p=0 [stop] right 180 d :p-1 uppitch 90 right 180 forward :unit uppitch 90 b :p-1 right 90 forward :unit left 90 c :p-1 uppitch 90 forward :unit uppitch 90 a :p-1 downpitch 180 forward :unit a :p-1 downpitch 90 forward :unit uppitch 90 c :p-1 left 90 forward :unit left 90 b :p-1 uppitch 90 forward :unit uppitch 90 d :p-1 rightroll 180 end to d :p if :p=0 [stop] right 180 c :p-1 forward :unit b :p-1 right 90 forward :unit left 90 b :p-1 right 180 forward :unit a :p-1 downpitch 90 forward :unit uppitch 90 a :p-1 downpitch 180 forward :unit b :p-1 right 90 forward :unit left 90 b :p-1 right 180 forward :unit c :p-1 rightroll 180 end |
And the first iterations:
Nice, isn’t it?