Barnsley fern



The Barnsley fern is a fractal named after the British mathematician Michael Barnsley who first described it in his book Fractals Everywhere. He made it to resemble the black spleenwort, Asplenium adiantum-nigrum.

History
The fern is one of the basic examples of self-similar sets, i.e. it is a mathematically generated pattern that can be reproducible at any magnification or reduction. Like the Sierpinski triangle, the Barnsley fern shows how graphically beautiful structures can be built from repetitive uses of mathematical formulas with computers. Barnsley's 1988 book Fractals Everywhere is based on the course which he taught for undergraduate and graduate students in the School of Mathematics, Georgia Institute of Technology, called Fractal Geometry. After publishing the book, a second course was developed, called Fractal Measure Theory. Barnsley's work has been a source of inspiration to graphic artists attempting to imitate nature with mathematical models.

The fern code developed by Barnsley is an example of an iterated function system (IFS) to create a fractal. This follows from the collage theorem. He has used fractals to model a diverse range of phenomena in science and technology, but most specifically plant structures.

"IFSs provide models for certain plants, leaves, and ferns, by virtue of the self-similarity which often occurs in branching structures in nature. But nature also exhibits randomness and variation from one level to the next; no two ferns are exactly alike, and the branching fronds become leaves at a smaller scale. V-variable fractals allow for such randomness and variability across scales, while at the same time admitting a continuous dependence on parameters which facilitates geometrical modelling. These factors allow us to make the hybrid biological models...

...we speculate that when a V -variable geometrical fractal model is found that has a good match to the geometry of a given plant, then there is a specific relationship between these code trees and the information stored in the genes of the plant." —Michael Barnsley et al.

Construction


Barnsley's fern uses four affine transformations. The formula for one transformation is the following:

f_w(x,y) = \begin{bmatrix}a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} e \\ f \end{bmatrix} $$ Barnsley shows the IFS code for his Black Spleenwort fern fractal as a matrix of values shown in a table. In the table, the columns "$a$" through "$f$" are the coefficients of the equation, and "$p$" represents the probability factor.


 * {|class="wikitable" style="text-align: right;"

! $w$ ! $a$ ! $b$ ! $c$ ! $d$ ! $e$ ! $f$ ! $p$ ! Portion generated These correspond to the following transformations:
 * 0
 * 0
 * 0
 * 0.16
 * 0
 * 0
 * 0.01
 * style="text-align: left;"| Stem
 * 0.85
 * 0.04
 * −0.04
 * 0.85
 * 0
 * 1.60
 * 0.85
 * style="text-align: left;"| Successively smaller leaflets
 * 0.20
 * −0.26
 * 0.23
 * 0.22
 * 0
 * 1.60
 * 0.07
 * style="text-align: left;"| Largest left-hand leaflet
 * −0.15
 * 0.28
 * 0.26
 * 0.24
 * 0
 * 0.44
 * 0.07
 * style="text-align: left;"| Largest right-hand leaflet
 * }
 * 0.28
 * 0.26
 * 0.24
 * 0
 * 0.44
 * 0.07
 * style="text-align: left;"| Largest right-hand leaflet
 * }


 * $$\begin{align}

f_1(x,y) &= \begin{bmatrix} 0.00 & 0.00 \\ 0.00 & 0.16 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \\[6px] f_2(x,y) &= \begin{bmatrix} 0.85 & 0.04 \\ -0.04 & 0.85 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} 0.00 \\ 1.60 \end{bmatrix} \\[6px] f_3(x,y) &= \begin{bmatrix} 0.20 & -0.26 \\ 0.23 & 0.22 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} 0.00 \\ 1.60 \end{bmatrix} \\[6px] f_4(x,y) &= \begin{bmatrix} -0.15 & 0.28 \\ 0.26 & 0.24 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} 0.00 \\ 0.44 \end{bmatrix} \end{align}$$

Computer generation
Though Barnsley's fern could in theory be plotted by hand with a pen and graph paper, the number of iterations necessary runs into the tens of thousands, which makes use of a computer practically mandatory. Many different computer models of Barnsley's fern are popular with contemporary mathematicians. As long as math is programmed correctly using Barnsley's matrix of constants, the same fern shape will be produced.

The first point drawn is at the origin ($f_{1}$) and then the new points are iteratively computed by randomly applying one of the following four coordinate transformations:



This coordinate transformation is chosen 1% of the time and just maps any point to a point in the first line segment at the base of the stem. In the iterative generation, it acts as a reset to the base of the stem. Crucially it does not reset exactly to (0,0) which allows it to fill in the base stem which is translated and serves as a kind of "kernel" from which all other sections of the fern are generated via transformations $f_{2}$, $f_{3}$, $f_{4}$.



This transformation encodes the self-similarity relationship of the entire fern with the sub-structure which consists of the fern with the removal of the section which includes the bottom two leaves. In the matrix representation, it can be seen to be a slight clockwise rotation, scaled to be slightly smaller and translated in the positive $y$ direction. In the iterative generation, this transformation is applied with probability 85% and is intuitively responsible for the generation of the main stem, and the successive vertical generation of the leaves on either side of the stem from their "original" leaves at the base.



This transformation encodes the self-similarity of the entire fern with the bottom left leaf. In the matrix representation, it is seen to be a near-90° counterclockwise rotation, scaled down to approximately 30% size with a translation in the positive $y$ direction. In the iterative generation, it is applied with probability 7% and is intuitively responsible for the generation of the lower-left leaf.



Similarly, this transformation encodes the self-similarity of the entire fern with the bottom right leaf. From its determinant it is easily seen to include a reflection and can be seen as a similar transformation as $x_{0} = 0, y_{0} = 0$ albeit with a reflection about the $y$-axis. In the iterative-generation, it is applied with probability 7% and is responsible for the generation of the bottom right leaf.

Mutant varieties


By playing with the coefficients, it is possible to create mutant fern varieties. In his paper on V-variable fractals, Barnsley calls this trait a superfractal.

One experimenter has come up with a table of coefficients to produce another remarkably naturally looking fern however, resembling the Cyclosorus or Thelypteridaceae fern. These are:
 * {|class="wikitable" style="text-align: right;"

! $w$ ! $a$ ! $b$ ! $c$ ! $d$ ! $e$ ! $f$ ! $p$
 * 0
 * 0
 * 0
 * 0.25
 * 0
 * −0.4
 * 0.02
 * 0.95
 * 0.005
 * −0.005
 * 0.93
 * −0.002
 * 0.5
 * 0.84
 * 0.035
 * −0.2
 * 0.16
 * 0.04
 * −0.09
 * 0.02
 * 0.07
 * −0.04
 * 0.2
 * 0.16
 * 0.04
 * 0.083
 * 0.12
 * 0.07
 * }
 * −0.04
 * 0.2
 * 0.16
 * 0.04
 * 0.083
 * 0.12
 * 0.07
 * }

Pseudocode
draw all pixels on screen white x = 0.0 y = 0.0 t = 0.0 xn = 0.0 yn = 0.0 while t < maximum iterations: r = random between 0 and 1 if r < 0.01: xn = 0.0 yn = 0.16 * y   else if r < 0.86: xn = 0.85 * x + 0.04 * y       yn = -0.04 * x + 0.85 * y + 1.6 else if r < 0.93: xn = 0.2 * x - 0.26 * y       yn = 0.23 * x + 0.22 * y + 1.6 else: xn = -0.15 * x + 0.28 * y       yn = 0.26 * x + 0.24 * y + 0.44 draw green pixel on screen at (xn, yn) x = xn   y = yn    increment t