Previous article: Accessory functions

Next article: Going for 3D

In the first 3 posts on this subject, we implemented the creation equation, added branching and dressed the resulting L-system fractals with color and width. Lovely.

These fractals all have binary branchings, i.e. whenever a branch splits, it splits into two directions. We can do better. We can branch into any number of directions we like as long as we specify the number of branches and the angle between them.

This doesn’t affect the maths of genetic fractals and as far as the Ruby code goes, there are some small changes to make:

- Add a few new columns to the CSV file (“branch” for the number of branches and “Branch Direction” for branching left, right or both);
- Add a “for” loop to the branch code and call the next branch repeatedly.

I won’t go through the code this time. If yo have made it this far, you will be able to understand the code from the comments.

### Repeating sections of the fractal

As you are messing around with the CSV file to cerate different fractals, you will have discovered that creating fractals that simply repeat themselves (as they do), is a bit painful. A lot of copy & pasting. What if…

What if we added another column or two where we indicate that we want to repeat a given range of the CSV file a number of times? No problem. There are now two additional columns “Repeats” for the number of times we want to repeat a section and “Repeat from” to indicate the line where we want to repeat from.

The Ruby code has been changed to do this. Read the comments … but to help you find the right comments:

- To repeat a section we simply re-set the value of s as per CSV instuction;
- For this to work, we need to copy the CSV file (in accFunctions) every time we start a new branch to ensure that repeat counter retains its initial value for sibling branches whilst it counts down for teh current branch
- Since we now repeat sections of the CSV file, the distance over which the branch grows (Dr) gets repeated. This isn’t quite what we want as Dr really should get smaller as we progress. We therefore make Dr relative to the previous value and pass its actual value to the next branch as it is called through “evaluate”.

The Ruby code may be found here.

Below are samples of the fractals we can now make. Not the different features: n-ary branches, left and/or right directions and repeats (well you can’t see that but you could if you look at the data of the last one).

Fractal-31

Fractal-32

Fractal-33

Fractal-34

Fractal-36 (“Autumn leaf”)

Fractal-37

Fractal-38

Previous article: Accessory functions

Next article: Going for 3D

Pingback: 2D genetic fractals makers guide (part 3): Accessory functions | Genetic Fractals Laboratory

There’s a real beauty in them, is there not?

LikeLike

I have a hypothesis that aesthetic forms are those generated by nature and replicated by man. Or could I just say that I agree 🙂

LikeLike

I like that idea.

LikeLiked by 1 person

Pingback: 2D genetic fractals makers guide (part 5): Going for 3D! | Genetic Fractals Laboratory