L-Systems Lab
Goals
To practice with the main dynamics of l-systems.
Setup
- Remember to start WSL if you are on Windows
- Pull down the new
LSystem-Labstarter code repository from the 361-F26 GitHub Organization withgit clone --recurse-submodules [URL]orgit submodule update --init --recursiveif you cloned without the recurse submodules command. - Set up Emscripten as normal:
cd emsdk ./emsdk install 3.1.49 ./emsdk activate 3.1.49 source ./emsdk_env.sh cd ..
Running the starter
With that all in place, the starter code is functional. Check it out with:
./compile-run.sh
Taxonomy
L-system rules can feel abstract, so let’s ground them in the typical phenotypes (i.e. the observed traits/patterns) of plants. In SetupGrammar do the following for each set of axioms and rules:
- Type up just the single axiom and rule, keeping the execution (
max_depth) to only one time step - Compile and run and observe what the starting state is and what the rule changes after one iteration. Write down both in the table on your worksheet
- Update the number of time steps to 4 to see how the rule plays out over more steps
- Write down a description of what that rule does at a high level
Here are the rules and axioms to observe:
- Axiom:
F, Rule:F -> FF - Axiom:
F, Rule:F -> F[+F][-F] - Axiom:
A, Rule:A -> F[+A][-A] - Axiom:
A, Rule:A-> F[++A][-A]FA
Changing Colors
L-system rules can cause growth, but they can also cause changes in state. Pick whichever starting rules you want from the previous taxonomy and then add a new state W that is a mature woody stem. This should happen when several lengths of F are together and probably makes sense to be brown and a bit thicker than the green stems. Here are some hints to achieve this:
- Add a new rule to get
Wfrom someF’s - Add another
else iftoDrawLSystemforWthat is based on the logic forFbut uses “green” and something larger for the line_width
Config Panel
It’s time to use the config panel!
- Uncomment the line
settings << config_panel;in the constructor and recompile to see the config panel. - The panel doesn’t do anything yet. To access values, you just use the name of the configuration setting defined at the top of the file. So to access the value for
ITERATIONS, you would doconfig.ITERATIONS(). EditSetupGrammarto use the config panel iterations value formax_depth. Remember to compile and run to try it out! - Add one or two more
VALUEs to the config at the top (remember to include a,between eachVALUE) and connect them to your code to explore effects of other parameters.
Submission
You aren’t required to submit labs in this class, but you can for an extra engagement credit. Complete the implementions above and then push it to GitHub:
git add LSysAnimate.cpp
git commit -m "finished config"
git push
Extra
There are a lot of extensions to L-systems to explore (and some of them you’ll explore in the homework as well). Try out some of these:
- Add probabilistic changes
- Add rules based on neighboring states as well as the state that changes
- Add decay rules
- Add more states and draw more things