The goal of this tutorial is to display phases of creating some of the basic fractals and branching structures in 2D and 3D. We will use Hoopsnake, a component that enables feedback loops and Rabbit, a component for L-systems and Cellular Automata.

There are more ways, how to describe fractals. Each fractal is determined by an axiom and production rules. These are applied to the axiom. The output, a result of the process subsequently becomes the input and the same rules are aplied again. We talk about iterations when the process is being repeated.

One of the most primitive fractals is Cantor set. We get the fractal by simple geometrical operation. The axiom is a line. The rules are: divide line into 3 equal segments, omit the middle one. Void stays empty. In the next iteration, there are 2 lines of 1/3 lenght as inputs, in the next one 4 lines and so on. We put the result of each iteration below the previous one. Hoopsnake is ideal to display this example.

The next fractal fragment, which we display is Sierpinski triangel. An axiom is an eqilateral triangel. We define transformation rules as generic data to hoopsnake. Each edge is divided in the middle. The existing vertex is then connected to adjacent middle-edge point to create a new triangel. In the first iteration we get 3 triangels becoming the input for the next iteration.

You can see the first 8 iterations in the gif above.

Simirarly, we can describe Koch snowflake with Hoopsnake use. The edges of the equilateral triangel (axiom) are divided to 3 parts. We get 4 points, where we connect points 1 and 2, points 3 and 4 and we create two lines between points 2 and 3, one rotate -60° around point 2, the second one 60° around point 3.

Another way (suitable for computer use) how to create fractal phases is L-system. For some fractals and branching structures mostly, it is more suitable than previous systems based on individual geometrical constructions. L-system is a rewriting system consisting of an alphabet of symbols used to make strings. Production rules expand each symbol into larger string of symbols in every iteration. Axiom is the initial string from which the construction begin. We can imagine, the whole fractal is created by a turtle (it’s tail is wet from ink) , which is moving and understands some simple commands represented by the alphabet.

We use following symbols:

F …move forward at distance L and draw a line

f …move forward at distance L without drawing a line

+ …turn left A degrees

– …turn right A degrees

[ …start a branch

] …end a branch(return to the position where branch started)

A/B/C/D.. placeholders

Let’ s rewrite the Koch snowflake to the L-system grammar. The axiom is, as we already know, an equilateral triangel. In the L-system alphabet it is represented by a string of symbols: **+F–F–F**, where the angle of rotation is 60°. F is an edge, which we want to divide at 3 parts and construct another equilateral triangel above the middle omitted segment. It means, that every **F** must transfer to **F+F–F+F **in the next iteration. Using rabbit component LSystem, we specify the axiom and production rules as well as the number of wanted iteration. Then we use the component Turtle, we connect the string of symbols coming out of LSystem and specify the lenght of the string and angle of rotation in this case. The result is a very same geometrical form as in previous example with Hoopsnake. The problem is, the lenght of the string F remains the same every iteration, which means the result is getting bigger (multiplication of curent length is not working properly).

We can display another well-known fractals, such as Hilbert curve, Peano curve or Dragon curve.

The curves above can be displayed using L-systems as well as classical, geometrical ways of construction or MRCM machines. However, the L-systems were developed primarily to imitate growth processes. Starting with following the rules of the algae cells division, today, we can model natural structures imitating various plants, trees, even mountains. These structures can be displayed only when using L-systems, neither from the classical ways of constructing fractals is suitable.

Here are examples of some of the 2D structures. The rules can be easy or more difficult:

The first branch in the picture below: axiom …**F**, rules …**F=F[+F]F[-F]F**

The last branch in the picture below: axiom …**A**, rules …**A= FF[F-[F[A+F[-[A][]]]][A+F[-F-A[]]]]F**

Each branch has a different axiom, production rules ad the angle of rotation.

For 3D structures, we use some extra symbols here:

\ …roll left A degrees

/ …roll right A degrees

^ …pitch up A degrees

& …pitch down A degrees

J …insert point at this position

“ …multiply current length by dL

! …multiply current thickness by dT

I played with the production rules to be simple enough, but give not too symetrical result. You can see the result in a gif below, when the angle of rotation is changing.

In the end, the last thing is to add some volume to the branching structure to get the shape of a tree form. For this, we just add Tube Settings component to the Turtle. We specify thickness, thickness scale and a profile curve of the beam. I changed the production rules to have a slightly different branches. At the top of each branch I added points, where I placed spheres of different radius and used desirable colors in preview.

GH file: FRACTALS