This article has participated in the Denver Nuggets Creators Camp 3 “More Productive writing” track, see details: Digg project | creators Camp 3 ongoing, “write” personal impact.

Starting with version 14.04.14, Lazy Nezumi Pro helps you draw complex shapes and fractals using the script engine’s L-system function.

This tutorial will teach you step-by-step how to use these functions.

A reference table for all functions and instruction symbols can be found on the script reference page.

define

L-system is defined as:

  • A set of symbols called the alphabet.
  • A string of these symbols, called axiom, defines the initial state of the system.
  • A set of rules describing how these symbols should be transformed at each iteration of the system.

The system will be iterated over many times, and the symbols will change according to the rules. This will produce a final string of symbols, which will be interpreted as instructions to move the pen by drawing shapes.

Example 1 – Koch Curve

Let’s start with a famous L-system: the Koch curve.

Alphabet: F, +, - Axiom: F rule: F = F-F+F+F-FCopy the code

If we start with axiom and replace F with a given rule, the system evolves as follows:

* * after the first iteration: F - F + F + F - F * * after the second iteration: F - F + F + F - F - F - F + F + F - F + F F + F + F F + F - F + F + F - F - F - F + F + F - F * * after the third iteration: F-F+F+F-F - F-F+F+F-F + F-F+F+F-F + F-F+F+F-F - F-F+F+F-F -\ F-F+F+F-F - F-F+F+F-F + F-F+F+F-F + F-F+F+F-F - F-F+F+F-F +\ F-F+F+F-F - F-F+F+F-F + F-F+F+F-F + F-F+F+F-F - F-F+F+F-F +\ F-F+F+F-F - F-F+F+F-F + F-F+F+F-F + F-F+F+F-F - F-F+F+F-F -\ F-F+F+F-F - F-F+F+F-F + F-F+F+F-F + F-F+F+F-F - F-F+F+F-FCopy the code

How do you draw things with this? We read the last string from left to right. Every time we see an F sign, we draw a line. If we encounter a – or + sign, turn 90 degrees to the left or right.

The figure below shows the results

L-system scripting

So how do we use it in Lazy Nezumi Pro? Start by creating a new preset. In its details panel, enable the script. Select custom mode and paste the following code into the text box:

lsysAxiom("F"); 
lsysRules("F=F-F+F+F-F"); 
lsysDrawSymbols("F"); 
lsysAngle(90); 
lsysLength(length); 
lsysIterations(iterations); 
lsysAdvance();
Copy the code

Then go ahead and click Compile. Because the program has two user variables, two parameter sliders should appear: Length (Lenth) and Iteration (Iteration). Click on their “…” Buttons that set their range to values more meaningful than [0..1].

The length (set using the lsyLength function) is the distance the pen moves each time the system encounters a DrawSymbol (F in this case, set using the lsysDrawSymbols function). A value around 10 would be a good place to start.

Iterations (set with the lsysIterations function) are the number of iterations that should be performed on the system after the program is compiled. Note this: If you have highly recursive rules, setting up a large number of iterations will take a long time to compute the final system string (and the application may be unresponsive for a while). Usually you don’t need more than 10 iterations, so set the range between 0 and 10.

All l-system functions except lsysAdvance are used only when the program is compiled. While you are drawing, lsysAdvance will traverse to the last L-System string until it finds a drawing symbol, at which point it will move the current pen position and return. This location is stored in the OX and OY variables.

If you open the Scripting Graph window, you can see a preview of the generated L-System when you change the parameters. Drawing l-systems in your art application can take some time, so it’s best to look at the preview first to get an idea of what you’ll get.