A procedural vegetation generator algorithm using L-system. This algorithm was implemented in JavaScript using P5.js library. This idea was inspired by the book "Procedural Content Generation in Games", chapter 5 "Grammars and L-systems with application to vegetation and levels"
Open the index.html file in a local server
If you want to modify any data, plase use the config.js file.
CNV_HEIGHT
andCNV_WIDTH
are the canva dimensions for P5.jsPACE
counts how many pixels there are in each edge of the picture (how many pixels it will "jump" from node to node)L_SYSTEM_LEFT
andL_SYSTEM_RIGHT
are the rules the algorithm will used. Please, read more information about that right bellowSEED
is the initial value to be transformed by the rulesINITIAL_X
andINITIAL_Y
are the coordinates of the first point of the curveEXPANSIONS
is the number of iterations the algorithm will execute in order to generate the image
First, you should know I've adopted the same alphabet from the book:
- f -> move forward
- + -> turn 30 degrees left
- - -> turn 30 degrees right
- [ -> adds the current position to the saved positions stack
- ] -> pops the last saved position from the stack
Consider A,B,C,D as statements and the following L-system:
- A -> B
- C -> D
You should rewrite the variables as:
L_SYSTEM_LEFT = [A, C]
L_SYSTEM_RIGHT = [B, D]
Consider writing the rules sorted by hierarchy if necessary.
You can find out more L-system for generating different types of vegetation on files/l_systems.js