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.

4 thoughts on “L-systems In Minecraft

  1. Awesome! Installed Scripcraft via Craftbukkit on my son’s home server today. He tried the tree and then cursed the size spending the next 10 minutes blowing it up only to create a giant ‘fun’ object. On the github repo I don’t see any lava, care to share that?

  2. Thanks for commenting. I am glad to hear about your son’s fractal gardening.

    I just updated the tree and fun classes so you can use different blocks, sizes, and generations. There are more instructions and updated code in the repo now.

    A lava fractal like the one in the picture can now be created by running:

    /js new fun(10,50,4)

    or use

    /js new fun(11,50,4)

    if you don’t want lava dripping everywhere.

  3. Thanks for the updated repo. I tried it against the latest scriptcraft jar and its throwing exceptions:
    2013-01-13 20:07:18 [INFO] loading /home/rc/craftbukkit/js-plugins/drone/drone.js
    2013-01-13 20:07:18 [SEVERE] javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: “getPlayerPos” is not defined. (#255) in at line number 255 (#27) in at line number 27 (#27) in at line number 27

Leave a comment