2D genetic fractals makers guide (part 4): Arbitrary branchings

fractal-36

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-31

fractal-32

Fractal-32

fractal-33

Fractal-33

fractal-34

Fractal-34

fractal-36

Fractal-36 (“Autumn leaf”)

fractal-37

Fractal-37

fractal-38

Fractal-38

Previous article: Accessory functions

Next article: Going for 3D

Advertisements

5 thoughts on “2D genetic fractals makers guide (part 4): Arbitrary branchings

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

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

So what do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s