At the top of every post on this site sits a band of characters: a “specimen”. None of it is drawn by hand. The band is the final state of a simulation (a chemical reaction, a chaotic orbit, a bundle of stock prices) rendered in ASCII. Below it, a label like the ones on laboratory slides sums up its genome. This post’s label reads:
specimen 0xf734 · gray-scott · f=0.030 k=0.0615
That is: seed 0xf734, the Gray-Scott family, and the two parameters that set its regime. The same text will always produce the same drawing, on the server and in any browser.
Why
A stock illustration teaches the reader nothing. A specimen shows the output of a real model, and its label leads to the post that explains its generator. The system follows three constraints. No two posts share a drawing, barring a rare collision. The drawing depends only on the post’s address, its tags and an optional explicit setting, never on the build date or on chance. And it stays plain: monochrome text, two intensities at most, no image to download.
From address to seed
Hashing: cyrb53
The starting point is the slug, the name of the post’s folder (specimens here). It does not change when the text is edited. It is hashed with cyrb53, a non-cryptographic hash function that bryc released into the public domain. It advances two 32-bit accumulators with Math.imul (integer multiplication modulo ) by odd constants, then mixes them one last time so that every input bit affects every output bit. The result fits in 53 bits, the largest range of integers a JavaScript number represents exactly.
Only the 16 low bits are used as the displayed seed:
| Step | Value |
|---|---|
| slug | specimens |
| cyrb53 | 4,219,924,838,151,988 (0xefdffd0f4f734) |
| seed (16 low bits) | 0xf734 |
| family | gray-scott (forced in the frontmatter) |
| preset drawn | solitons, f = 0.030, k = 0.062 |
| after a small jitter | f = 0.0300, k = 0.0615 |
Sixteen bits make 65,536 seeds. By the birthday paradox, the probability that at least two posts out of a hundred share a seed is about . Even then, they only share a specimen if they also fall in the same family, and their secondary tags can still tell them apart.
Pseudorandom generator: sfc32
The seed feeds sfc32 (Small Fast Counting), a generator written by Chris Doty-Humphrey and shipped with PractRand, his statistical test suite. Its state is four 32-bit words, one of them a counter that guarantees a minimum period of (the average period is around ); PractRand lists it as the fastest of its recommended 32-bit generators. The engine seeds it with a splitmix-style mixer1 and discards the first twelve outputs:
export function createRng(seed: number, stream = 0): Rng {
let s = (seed ^ Math.imul(stream + 1, 0x9e3779b9)) | 0;
// ... four calls to a splitmix32 mixer fill a, b, c, d
for (let i = 0; i < 12; i++) next();
return next;
}
The stream argument gives independent sequences for the same seed: stream 11 draws the parameters, stream 12 the modulations, stream 1 the Gray-Scott initial condition, streams 100 and up the Brownian paths. Adding a draw to one stream therefore never shifts the others.
From tag to generator
The post’s first tag that appears in the family table picks the generator; with no match, it is Gray-Scott. The parameters are then drawn in two steps:
export function deriveParams(generator: GeneratorId, seed: string, modulators: readonly string[]) {
const g = GENERATORS[generator];
const s = seedToInt(seed);
const key = [...new Set(modulators)].sort().join(',');
return { ...g.params(createRng(s, 11)), ...g.nudges(createRng(hash32(key, s), 12)) };
}
The identity (params) depends on the seed alone: for Gray-Scott, one preset out of eight known regimes and a small jitter on . The modulations (nudges) depend on the seed and on the sorted set of the other tags: initial density, mirror symmetry, choice of character ramp. Sorting the tags makes the result independent of their order; adding a secondary tag retouches the drawing without changing its nature.
Freezing or forcing a specimen
The frontmatter’s specimen field overrides everything else:
specimen:
generator: attractor # forces the family
seed: "0x3fa9" # or any string, which gets hashed
params: { a: -1.4 } # overrides one parameter
A hexadecimal seed is read as is; any other string is hashed, so seed: "spring" works too. An unknown generator triggers a warning at build time and the family falls back to the one from the tags.
The same drawing everywhere
The drawing is computed twice: at build time by Node, then replayed in the reader’s browser. Both must end on exactly the same characters. For integers this is easy: Math.imul, shifts and XOR are defined exactly. For floating point, IEEE 754 requires , , , and the square root to be correctly rounded: same input, same output, bit for bit, on any machine.
The trouble with Math.sin
Transcendental functions get no such guarantee. The ECMAScript specification states that sin, cos, log, exp and a few others are “not precisely specified” and leaves “latitude in the choice of approximation algorithms”. V8, SpiderMonkey and JavaScriptCore may therefore disagree on the last bit. For a strange attractor that rules them out: sensitivity to initial conditions blows a one-bit difference up into an entirely different orbit in under a hundred iterations.
dmath
So the engine ships its own sin, cos, log and exp, written with the basic operations and Math.floor only. For the sine, the argument is brought close to zero by a Cody-Waite reduction: is split into a 33-bit high part and a remainder, so that is subtracted without rounding error for the arguments that come up; a Taylor polynomial evaluated with Horner’s scheme does the rest.
export function sin(x: number): number {
const k = Math.floor(x * INV_PIO2 + 0.5);
const r = x - k * PIO2_HI - k * PIO2_LO;
switch (k & 3) {
case 0: return sinPoly(r);
case 1: return cosPoly(r);
case 2: return -sinPoly(r);
default: return -cosPoly(r);
}
}
The logarithm brings the mantissa into by multiplying by 2, then sums the series . The accuracy, around , is more than enough; what matters is that the result is the same everywhere.
From field to text
Each generator produces a scalar field normalised to , one value per cell of the character grid: 120 columns by 14 rows for a banner, 96 by 3 for the strips in the list of posts. A ramp, from sparse to dense, turns each value into a character. For Gray-Scott, for instance:
.:-=+*#%@
The value becomes the character at index (capped at 9). The first levels of the ramp (45%, rounded) print in a light tone, the rest in full blue: the drawing never uses more than two intensities. The ramps stick to punctuation and Latin-1 symbols, so that the self-hosted monospace font covers every glyph. A character cell being about 0.6 times as wide as it is tall, the spatial generators (all but the Brownian one) correct for that ratio so that shapes stay round on screen.
Replaying the growth
At build time the simulation runs to the end and its final state is written as static HTML: nothing to load, no layout shift, and the page reads fine without JavaScript. In the browser, when the specimen scrolls into view, the same simulation starts over and replays its growth in about 2.4 seconds.
The guarantee of landing back on the build’s image rests on a contract: all of a generator’s work is a fixed sequence of total units (Gray-Scott steps, attractor points, Brownian columns). Doing it in one call at build time or in a thousand pieces spread over animation frames runs exactly the same operations in the same order. A slow device takes longer without skipping a step. At the end, as a safety net, the script puts back the exact text of the original HTML and, in development, reports any difference. With prefers-reduced-motion, only the final state is shown. The pointer can then stir the field locally, and it settles back to its final state on its own.
The home page specimen goes further: once it reaches its final image, it keeps going. Each generator has an endless regime (the Brownian paths scroll by, the DLA cluster melts and grows back), computed in a worker so the page stays responsive.
The seven generators
| Generator | Tag | In one sentence |
|---|---|---|
| gray-scott | default | Two chemical species that diffuse and react draw spots, mazes and corals. |
| attractor | maths | The density histogram of a chaotic Clifford or Peter de Jong orbit. |
| brownian | finance | A bundle of geometric Brownian motion paths, the Black-Scholes model. |
| lenia | ai | A continuous cellular automaton in which artificial creatures emerge. |
| automaton | code | A cellular automaton, elementary or Life-like: a local rule that is enough to compute. |
| isolines | maps | The contour lines of a terrain drawn from fractal noise. |
| dla | projects | Diffusion-limited aggregation, a cluster that grows one particle at a time. |
Notes
-
Steele, Lea and Flood (2014) introduced SplitMix; the 32-bit variant used here adds the golden ratio constant (
0x9e3779b9) on every call and applies the MurmurHash3 finalizer. ↩