Page 1 of 1

L system treegen description

Posted: Wed Feb 13, 2013 00:30
by jin_xi
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:

Image

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.

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

Posted: Wed Feb 13, 2013 00:46
by Tester 2502
Now that is kind of cool. but what I do to make a treegen?

Posted: Wed Feb 13, 2013 01:02
by jin_xi
save this as init.lua in a folder named treegentest in your mods folder: https://gist.github.com/obneq/4780325
use /giveme treegentest:treespawner to get a spawner

Posted: Wed Feb 13, 2013 08:28
by pandaro
thanks for the explanation.
maybe I can make a tree.

Posted: Wed Feb 13, 2013 15:58
by PilzAdam
jin_xi, can you write this description at the Minetest dev wiki (http://dev.minetest.net/)?

Posted: Wed Feb 13, 2013 21:11
by socramazibi
Thanks for the info, very interesting.

One could build a house?

Thanks

Posted: Fri Feb 22, 2013 14:52
by sfan5
Awesome system of generating trees/other objects!
+1

Re: L system treegen description

Posted: Sun Jan 11, 2015 23:07
by 4aiman
I know this is an old thread, but I've a reason:
Does it work properly for anyone?

For me it generates the tree, but it also generates an enormous cube of a random chosen node (depends on installed mods). That is true for any mod I've found here, at minetest.net.

Re: L system treegen description

Posted: Thu Jan 22, 2015 04:15
by Sokomine
4aiman wrote: For me it generates the tree, but it also generates an enormous cube of a random chosen node (depends on installed mods). That is true for any mod I've found here, at minetest.net.
I havn't tried it personally, but VanessaE reported something similar in the "post your screenshot" thread. Sounded like the same bug.

Re: L system treegen description

Posted: Thu Jan 22, 2015 05:44
by 4aiman
Thanks, Sokomine!

Does anyone know whether L-system trees are still deemed supported?
LVM has it's own downsides after all.

Re: L system treegen description

Posted: Thu Jan 22, 2015 05:46
by Sokomine
4aiman wrote: Does anyone know whether L-system trees are still deemed supported?
Yes, they're still supported. Moretrees are all L-system trees.

Re: L system treegen description

Posted: Thu Jan 22, 2015 08:47
by 4aiman
I've reported one of my messages to bring moderators' attention to this bug (and to be aware whether someone would fix it) :)

Re: L system treegen description

Posted: Thu Jan 22, 2015 10:28
by jin_xi
ii dont think reporting your own post is the right way to go about something like this. Its already fixed in a recent commit.