For my senior-level computer graphics course, I made an L-Systems interpreter that parses a JSON-formatted grammar into a scene file, which then could be made into an image using the customized renderer we'd been working on in that class!
It supported multiple colors, stochastic variation, and the ability to define arbitrary triangle meshes, which is how I implemented leaves and petals.
For example, the flower on the bottom right was generated by:
{
"delta" : 18,
"axiom" : "'+P",
"length" : 3,
"radius" : 0.2,
"generations" : 5,
"radiusRatio" : 0.8,
"lengthRatio" : 0.9,
"productions" : {
"P" : "I+[P+R]--//[--L]I[++L]-[PR]++PR",
"I" : "FS[//&&L][//^^L]FS",
"S" : ["SFS",
"S",
"S[//&&L][//^^L]FS"],
"L" : "[{+f-ff-f+|+f-ff-f}]",
"R" : ["[-D/W//W//W//W//W//W//W//W//W]",
"[-D'/W//W//W//W//W//W//W//W//W]",
"[-D''/W//W//W//W//W//W//W//W//W]"],
"D" : "FF",
"W" : "['^F][''{&&&&--f++f|--f++f}]"
}
}
The first few lines lay out some of the basic properties of the grammar. How long or big stems should be, what angle branches should take from their point of origin, how many recursions the fractal should generate for, etc. The productions describe how various parts of the object should be built. P is the axiom/root point, S is a stem segment, L is a leaf, R is a flower, and W is a petal, for example. F is a forward command, to generate a stem or edge. +, - , &, ^, , /, and | rotate the next element in various directions. [ and ] are push/pop commands that allow the structure to branch off into multiple directions. { and } toggle between cylinder-mode and triangle-mesh mode. ' iterates through a list of colors.
L-Systems are a really neat example of how mathematics and fractals are present in the natural world! By laying out a (relatively) simple repeating pattern and just introducing a little bit of variance to it, it's possible to generate quite natural looking foliage out of just basic shapes.
