- Options
Fern 2
This Fern is an L-System Fractal. It is generated by the L-System Algorithm with the following settings:
const fern2: Ruleset = {
color: "#3cf7d2",
minIterations: 1,
maxIterations: 9,
axiom: "Y",
replace: {
X: "X[-FFF][+FFF]FX",
Y: "YFX[+Y][-Y]",
},
angle: 25.7,
initLength: (ctx) => ctx.height * 0.6,
initTranslation: (ctx) => [ctx.width / 2, ctx.height],
divideFactor: 2.05,
};
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),
};