- Options
Fern 3
This Fern is an L-System Fractal. It is generated by the L-System Algorithm with the following settings:
const fern3: Ruleset = {
color: "#91fc8e",
minIterations: 1,
maxIterations: 5,
axiom: "F",
replace: {
F: "F[+FF][-FF]F[-F][+F]F",
},
angle: 22.5,
initLength: (ctx) => ctx.height * 0.9,
initTranslation: (ctx) => [ctx.width / 2, ctx.height],
divideFactor: 3,
};
Ferns are cool, and they are one of the original applications of L-Systems. There is a great book out there called ABOP - The Algorithmic Beauty of Plants. It covers how to model plants with algorithms in-depth and incidentally, and also has a long section on how to use L-Systems to generate grasses, bushes, trees and ferns.
This fractal, by its nature as an L-System, is also related to all the other L-System Fractals. A few you can check out: Hilbert Curve, Sierpinski Triangle, and the Lévy Curve.
You can also check out the other plant-like structures from the Fractal Garden – the Barnsley Fern and the Fractal Canopy.
The alphabet to instructions set used to draw this fractal are the same as for the other L-Systems:
const drawRules: Record<string, () => void> = {
V: () => {},
W: () => {},
X: () => {},
Y: () => {},
Z: () => {},
G: drawForward,
F: drawForward,
f: () => ctx.translate(0, -len),
"+": () => ctx.rotate(angle * rotationDirection),
"-": () => ctx.rotate(angle * -rotationDirection),
"|": () => ctx.rotate(180),
"[": () => ctx.push(),
"]": () => ctx.pop(),
"#": () => (ctx.lineWidth = weight += weightIncrement) ,
"!": () => (ctx.lineWidth = weight -= weightIncrement) ,
">": () => (len *= scale),
"<": () => (len /= scale),
"&": () => (rotationDirection = -rotationDirection),
"(": () => (angle += angleIncrement),
")": () => (angle -= angleIncrement),
};