Barnsley Fern (IFS) — Explanation & Equations
Barnsley Fern (IFS) — Explanation & Equations
An English explanation focusing on the core formulas behind the classic Iterated Function System fern, plus a single‑file p5.js demo.
1) What the code does (English)
We maintain a single point $(x_n, y_n)$. At each step we randomly choose one of four affine maps and update the point. Repeating this (the so‑called chaos game) produces the fern's self‑similar structure.
Here $i\in\{1,2,3,4\}$. The four maps and their probabilities are chosen to sculpt the stem, the main leaflet mass, and two side leaflets.
2) Random selection (probabilities)
Draw $r\sim\mathcal U(0,1)$. Using cumulative probabilities $\mathrm{CDF}=(0.01,\,0.86,\,0.93,\,1.00)$, pick $i$ as:
These correspond to probabilities $(p_1,p_2,p_3,p_4)=(0.01,0.85,0.07,0.07)$.
3) The four affine transforms
Standard Barnsley coefficients (stem, main mass, left leaflet, right leaflet):
$T_1$ compresses towards the stem; $T_2$ generates most of the mass (slight rotation + scale + upward shift); $T_3, T_4$ add side leaflets.
4) Mapping math coordinates to canvas pixels
Given target extents $x\in[x_{\min},x_{\max}]$ and $y\in[y_{\min},y_{\max}]$, canvas width $W$, height $H$:
For the canonical fern: $x_{\min}
Comments
Post a Comment