Fern Fractals

(*Barnsley fern *)
p1 = 0.01; (*probability for stem*)
p2 = 0.85; (*successively smaller leaflets*)
p3 = 0.07; (*largest left-hand leaflet; p4 = 0.07, largest right-hand leaflet*)

(*multiplies matrix + point {x,y} to successively generate points*)
f1 = Compile[{{point,_Real,1}},Dot[{{0.,0.},{0.,.16}},point]];
f2= Compile[{{point,_Real,1}},Dot[{{.85,.04},{-.04,.85}},point] + {0.,1.6}];
f3= Compile[{{point,_Real,1}},Dot[{{.2,-.26},{.23,.22}},point] + {0.,1.6}];
f4= Compile[{{point,_Real,1}},Dot[{{-.15,.28},{.26,.24}},point] + {0.,.44}];

(*Thelypteridaceae fern *)
p1t = 0.02; (*probability for stem*)
p2t = 0.84; (*successively smaller leaflets*)

(*multiplies matrix + point {x,y} to successively generate points*)
f1t= Compile[{{point,_Real,1}},Dot[{{0.,0.},{0.,.25}},point] + {0.,-.4}];
f2t= Compile[{{point,_Real,1}},Dot[{{.95,.005},{-.005,.93}},point] + {-.002,.5}];
f3t= Compile[{{point,_Real,1}},Dot[{{.035,-.2},{.16,.04}},point] + {-.09,.02}];
f4t= Compile[{{point,_Real,1}},Dot[{{-.04,.2},{.16,.04}},point] + {.083,.12}];

(*Leptosporangiate fern*)
(*multiplies matrix + point {x,y} to successively generate points*)
f1l= Compile[{{point,_Real,1}},Dot[{{0.,0.},{0.,.25}},point] + {0.,-.14}];
f2l= Compile[{{point,_Real,1}},Dot[{{.85,.02},{-.02,.83}},point] + {0.,1.}];
f3l= Compile[{{point,_Real,1}},Dot[{{.09,-.28},{.3,.11}},point] + {0.,.6}];
f4l= Compile[{{point,_Real,1}},Dot[{{-.09,.28},{.3,.09}},point] + {0.,.7}];

point = {0.,0.};

generatePointB[point_] :=(r=RandomReal[];
Which[p1 < r < p1+p2,f2[point],
p1+p2 < r < p1+p2+p3,f3[point],
p1+p2+p3<r,f4[point],
r<p1,f1[point]])

generatePointT[point_] :=(r=RandomReal[];
Which[p1t < r < p1t+p2t,f2t[point],
p1t+p2t < r < p1t+p2t+p3,f3t[point],
p1t+p2t+p3<r,f4t[point],
r<p1t,f1[point]])

generatePointL[point_] :=(r=RandomReal[];
Which[p1t < r < p1t+p2t,f2l[point],
p1t+p2t < r < p1t+p2t+p3,f3l[point],
p1t+p2t+p3<r,f4l[point],
r<p1t,f1l[point]])

Manipulate[
ListPlot[
NestList[
Which[
type==="Barnsley",generatePointB,
type === "Thelypteridaceae",generatePointT,
type === "Leptosporangiate",generatePointL
],point,iterations
],
PlotStyle->Green,Background -> Black,Axes->False,AspectRatio->1,ImageSize->1.1{400,400}],
{{iterations,100},0,20000,100,Appearance->"Labeled"},{{type,"Barnsley","fern type"},{"Barnsley","Thelypteridaceae","Leptosporangiate"},ControlType->RadioButtonBar},
SaveDefinitions ->True]

CAPTION

This Demonstration plots three types of ferns: Barnsley, Thelypteridaceae, and Leptosporangiate. The ferns are obtained by repeatedly applying one of four affine transformations chosen randomly, starting at the origin. By adjusting matrix coefficients and probabilities, we can generate different types of ferns.

THIS NOTEBOOK IS THE SOURCE CODE FROM

Elaine Lin

"Fern Fractals"
 http://demonstrations.wolfram.com/FernFractals/
 Wolfram Demonstrations Project
 Published: February 12, 2015

A full-function Wolfram Mathematica system is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »