Growing binary roots on a canvas
The roots under the name on this site are made of zeros and ones. They grow when the page loads and come out different every time. This is how they work.
The soil is a grid
Text drawn at free positions overlaps and turns into mush. So the area below the ground line is treated as a grid of character cells, and a cell can hold one digit at most.
cw = Math.max(9.5, Math.min(18, mark.width / 45)); // cell width
rh = cw * 1.32; // row height
cols = Math.ceil(box.width / cw);
rows = Math.floor((box.height - 36) / rh) - 2;
The cell size follows the width of the name. A large name on a wide screen grows large digits, a small one on a phone grows small digits.
A root is a tip that walks down
Each root is a tip with a column, a row, a sideways direction and a strength. A handful of tips start in the row above the grid, spread under the letters.
tips.push({ c: col, r: -1, dx: 0, s: 0.9, gen: 0, flat: 0 });
On every step a tip moves one row down and dx columns sideways, so it runs straight or on a diagonal. Now and then it picks a new direction. Main roots change often and mostly go down. Side roots keep their diagonal for longer.
if (Math.random() < (t.gen ? 0.14 : 0.3)) {
t.dx = t.gen ? (Math.random() < 0.6 ? t.dx : 0)
: Math.floor(Math.random() * 3) - 1;
}
Strength decides size and brightness
Strength falls a little on each step. The digit is drawn larger and brighter the stronger the root is, so roots thin out toward the tips the way real ones do.
ctx.globalAlpha = Math.min(1, 0.2 + t.s * 0.9);
ctx.font = '500 ' + (cw * (0.95 + 0.5 * t.s)) + 'px "Plex Mono"';
ctx.fillText(Math.random() < 0.5 ? '0' : '1', x, y);
The rate of decay is set so that a main root arrives at the bottom with about 40 percent of its strength, whatever the depth of the grid:
fade = Math.pow(0.42, 1 / rows);
Branching
A strong enough tip sometimes leaves a child behind. The child starts with two thirds of the parent’s strength and heads off to one side.
The chance of branching is divided by the number of rows. Without that, deep soil on a phone would branch far more often than shallow soil on a desktop, and the two would look nothing alike.
if (t.s > 0.3 && t.gen < 2 && Math.random() < (t.gen ? 2.2 : 4.5) / rows) {
next.push({ c: t.c, r: t.r, dx: side, s: t.s * 0.66, gen: t.gen + 1 });
}
Collisions
Every drawn cell is remembered. When the next cell is taken, a main root steps around it and a side root simply ends. Ending is what keeps the picture open: if side roots were rerouted too, they would pile up in neighbouring columns and form solid blocks of digits.
Growing over time
One step runs every 55 milliseconds until no tips are left, which takes about a second. Visitors who have asked their system for reduced motion get the finished roots at once:
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
while (tips.length) step();
} else {
timer = setInterval(step, 55);
}
The drawing starts only after both fonts have loaded, because the position of the name decides where the roots begin.