Jack'O Lantern Fractal

L-systems In Minecraft

In this post I use ScriptCraft, Minecraft, and L-systems to create fun in-game fractals and discuss how you can too.

ScriptCraft

ScriptCraft is a Minecraft mod that allows you to run JavaScript inside the game using the Java Rhino library.  Walter Higgins the creator of Scriptcraft modeled the library’s API after the programming language Logo which is basically a Lisp with turtle graphics (more on that in a bit).  Lucky for us having turtle graphics makes working with L-systems super easy since a turtle interpreter is a natural way to render L-systems.

L-systems

L-systems were originally created by a Hungarian botanist named Aristid Lindenmayer who was interested in modeling plant growth.  You can model arboreal growth, brush and shrubs, and also roots (by changing the modeling environment a bit to bring about different tropisms). You can do more than model trees though–there are tons of interesting fractals to make like Koch curves, Dragon curves, and Sierpinksi’s Triangles.

Learning exactly how L-systems work requires a bit of knowledge about grammars–a topic which I slept through while in Computing Theory class.  I’ve picked up some knowledge since then, but to keep this post short I’ll avoid any grammar shenanigans and say an L-system is simply a series of commands that change over time due to a corresponding set of rules.  So if you change the starting commands and/or the set of rules you will get different types of structures like this romantic torch-lit fractal which my turtle built just for you baby (by following the commands).

Torch-lit Fractal

Torch-lit Fractal

Putting It All Together

In order to start drawing L-systems in Minecraft, I installed ScriptCraft following the instructions on the ScriptCraft Github repo and then went searching for a JavaScript L-system library I could poach.  I settled on John Snyder’s L-system implementation which is BSD licensed and can be found on his blog.  He also has a turtle implementation which would be a good candidate for wrapping around the ScriptCraft Drone (ScriptCraft’s turtle).

Converting this L-system implementation to work in ScriptCraft was a breeze and you can see the code in the Github repo I created for this project.  Follow the installation instructions there if you want to start creating L-system fractals in Minecraft….like this one:

Petrified Tree

Petrified Tree

Oh and make you sure experiment with lava and water for cool 2D fractals turned 3D:

2D-3D Lava Fractal

2D-3D Lava Fractal

Email me any cool fractals you make–especially if you have better texture packs and lighting mods installed than I.  Also if you liked this, check out my post on Visualizing Sorting  Algorithms.