## L system treegen description

jin_xi
Member
Posts: 165
Joined: Mon Jul 02, 2012 18:19

### L system treegen description

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.
Last edited by jin_xi on Fri Feb 22, 2013 14:11, edited 1 time in total.

Tester 2502
New member
Posts: 9
Joined: Tue Feb 12, 2013 23:57
Now that is kind of cool. but what I do to make a treegen?

jin_xi
Member
Posts: 165
Joined: Mon Jul 02, 2012 18:19
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

pandaro
Member
Posts: 320
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind
thanks for the explanation.
maybe I can make a tree.
sorry for bad english
Linux debian 7 wheezy 64
kde

Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
jin_xi, can you write this description at the Minetest dev wiki (http://dev.minetest.net/)?
Last edited by PilzAdam on Wed Feb 13, 2013 15:58, edited 1 time in total.

socramazibi
Member
Posts: 81
Joined: Mon Jan 28, 2013 12:29
Location: España
Thanks for the info, very interesting.

One could build a house?

Thanks
Forgive my English, but it is the translator of google.My Spanish.
My mod:
Pictures wool 1.0 3x5 , Charcoal+Textures , Map

sfan5
Moderator
Posts: 3895
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5
Location: Germany
Awesome system of generating trees/other objects!
+1
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

### Re: L system treegen description

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.

Sokomine
Member
Posts: 4017
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

### Re: L system treegen description

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.
A list of my mods can be found here.

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

### Re: L system treegen description

Thanks, Sokomine!

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

Sokomine
Member
Posts: 4017
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

### Re: L system treegen description

4aiman wrote: Does anyone know whether L-system trees are still deemed supported?
Yes, they're still supported. Moretrees are all L-system trees.
A list of my mods can be found here.

4aiman
Member
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

### Re: L system treegen description

I've reported one of my messages to bring moderators' attention to this bug (and to be aware whether someone would fix it) :)

jin_xi
Member
Posts: 165
Joined: Mon Jul 02, 2012 18:19

### Re: L system treegen description

ii dont think reporting your own post is the right way to go about something like this. Its already fixed in a recent commit.

### Who is online

Users browsing this forum: No registered users and 2 guests