### L system treegen description

Posted:

**Wed Feb 13, 2013 00:30**hey all, this is a short description of the l-system treegen that RealBadAngel has made for minetest.

basically the l-system is much like turtle graphics. your turtle starts on its spawn position, facing up.

you can give it some commands, to control what it is doing:

G - move forward one unit with the pen up

F - move forward one unit with the pen down drawing trunks and branches

f - move forward one unit with the pen down drawing leaves (100% chance)

T - move forward one unit with the pen down drawing trunks only

R - move forward one unit with the pen down placing fruit

+ - yaw the turtle right by angle parameter

- - yaw the turtle left by angle parameter

& - pitch the turtle down by angle parameter

^ - pitch the turtle up by angle parameter

/ - roll the turtle to the right by angle parameter

* - roll the turtle to the left by angle parameter

i am talking about the RULES part later. now we're just talking about the AXIOM.

if your axiom is something like TTTT then you will get 4 vertically stacked nodes of trunk material. the turtle starts at its spawn position, and does the step T, which is "move forward one unit with the pen down drawing trunks only". Remember the turtle is facing up, which it why we're getting a vertical structure.

Other commands work as expected, so we can do something like TTTTT&TTTTT&TTTTT&TTTTT to get a square of trunk material if the angle is set to 90 degrees. always remember which way your turtle is facing to get the expected results, at the end of this axiom it will be back on its spawn position, lying on its side, facing left. this is a bit complicated, which is why there are the stack operations.

[ - save in stack current state info

] - recover from stack state info

you can use these to save and recall the position of your turtle. here is an example:

TTTTT[^TTTTT][&TTTTT]

with the angle set to 60 degrees this should give you a Y shape. The turtle starts at spawn pos, facing up. it goes forwards (up!) 5 times, placing trunks. then the position and rotation are saved. The part wrapped in [] is done, and the turtle is back to where it was before. Now the 2nd branch is done, starting from the same pos as the first.

Ok, this covers basic turtle graphics, but its only called L-system if the replacement rules and recursions come into play.

Everytime you use an Aa, Bb, Cc or Dd in your axiom it will be replaced with whatever the corresponding rule is. This will be done every recursion. An example:

Lets say we want to create a fractal Y shape: its like a Y but both ends of it are themselves shaped like Ys. With 3 recursions this should give us a total of 8 (2^3) ends.

here is the axiom: TTTTTA now rule A needs to create the branch. If rule A itself uses an A at its end, that will be replaced again, and so on... rule a is this: [^TTTTTA][&TTTTTA].

lets look at it step by step: first we do the axiom, just a vertical trunk. then on its top is added one V shape (rule A). All in all the tree now looks like this: TTTTT[^TTTTTA][&TTTTTA] (the first A has been replaced by the whole of rule A). in the next step both A's at the end of the branches are replaced, again with the whole of rule A, giving this:

TTTTT[^TTTTT[^TTTTTA][&TTTTTA]][&TTTTT[^TTTTTA][&TTTTTA]]

and after the 3rd recursion this is the result:

ok i hope this clears thing up for everyone, have fun

update:

http://ompldr.org/vaGp4NQ/treegentest.zip this is a small mod to edit your treedef ingame. it makes it easier to experiment with the system.

because formspecs use [ and ] themselves it is replaced with push and pop for display. when writing rules you can use [ and ] without problem.

basically the l-system is much like turtle graphics. your turtle starts on its spawn position, facing up.

you can give it some commands, to control what it is doing:

G - move forward one unit with the pen up

F - move forward one unit with the pen down drawing trunks and branches

f - move forward one unit with the pen down drawing leaves (100% chance)

T - move forward one unit with the pen down drawing trunks only

R - move forward one unit with the pen down placing fruit

+ - yaw the turtle right by angle parameter

- - yaw the turtle left by angle parameter

& - pitch the turtle down by angle parameter

^ - pitch the turtle up by angle parameter

/ - roll the turtle to the right by angle parameter

* - roll the turtle to the left by angle parameter

i am talking about the RULES part later. now we're just talking about the AXIOM.

if your axiom is something like TTTT then you will get 4 vertically stacked nodes of trunk material. the turtle starts at its spawn position, and does the step T, which is "move forward one unit with the pen down drawing trunks only". Remember the turtle is facing up, which it why we're getting a vertical structure.

Other commands work as expected, so we can do something like TTTTT&TTTTT&TTTTT&TTTTT to get a square of trunk material if the angle is set to 90 degrees. always remember which way your turtle is facing to get the expected results, at the end of this axiom it will be back on its spawn position, lying on its side, facing left. this is a bit complicated, which is why there are the stack operations.

[ - save in stack current state info

] - recover from stack state info

you can use these to save and recall the position of your turtle. here is an example:

TTTTT[^TTTTT][&TTTTT]

with the angle set to 60 degrees this should give you a Y shape. The turtle starts at spawn pos, facing up. it goes forwards (up!) 5 times, placing trunks. then the position and rotation are saved. The part wrapped in [] is done, and the turtle is back to where it was before. Now the 2nd branch is done, starting from the same pos as the first.

Ok, this covers basic turtle graphics, but its only called L-system if the replacement rules and recursions come into play.

Everytime you use an Aa, Bb, Cc or Dd in your axiom it will be replaced with whatever the corresponding rule is. This will be done every recursion. An example:

Lets say we want to create a fractal Y shape: its like a Y but both ends of it are themselves shaped like Ys. With 3 recursions this should give us a total of 8 (2^3) ends.

here is the axiom: TTTTTA now rule A needs to create the branch. If rule A itself uses an A at its end, that will be replaced again, and so on... rule a is this: [^TTTTTA][&TTTTTA].

lets look at it step by step: first we do the axiom, just a vertical trunk. then on its top is added one V shape (rule A). All in all the tree now looks like this: TTTTT[^TTTTTA][&TTTTTA] (the first A has been replaced by the whole of rule A). in the next step both A's at the end of the branches are replaced, again with the whole of rule A, giving this:

TTTTT[^TTTTT[^TTTTTA][&TTTTTA]][&TTTTT[^TTTTTA][&TTTTTA]]

and after the 3rd recursion this is the result:

ok i hope this clears thing up for everyone, have fun

update:

http://ompldr.org/vaGp4NQ/treegentest.zip this is a small mod to edit your treedef ingame. it makes it easier to experiment with the system.

because formspecs use [ and ] themselves it is replaced with push and pop for display. when writing rules you can use [ and ] without problem.