write a single index.html with a canvas that grows a snowflake using reiter's hexagonal cellular automaton. hex grid, one frozen seed cell in the center, background vapor level beta, diffusion alpha, and add constant gamma. step it every frame and draw frozen cells in white on dark navy. vanilla js, no libraries, under 150 lines.
121 lines and it works first try: alpha 1, beta 0.4, gamma 0.001, one seed, six arms with little side branches. but it's one step per frame, so live it took ~15s to look like a snowflake and ~24s to get big. the video is sped up about 3x. the grid is a rhombus, so if you leave it running the ice creeps along the edges, and the cells are flat white hexes drawn one fill at a time.
// filename: index.html (step 1, the whole CA step)
function step() {
const u = new Float32Array(N * N);
const v = new Float32Array(N * N);
// split into receptive (u) and non-receptive (v) parts
for (let r = 0; r < N; r++) {
for (let q = 0; q < N; q++) {
const i = idx(q, r);
let receptive = frozen[i] === 1;
if (!receptive && !isEdge(q, r)) {
for (const [dq, dr] of NB) {
if (frozen[idx(q + dq, r + dr)]) { receptive = true; break; }
}
}
if (receptive) { u[i] = s[i] + GAMMA; v[i] = 0; }
else { u[i] = 0; v[i] = s[i]; }
}
}
// diffuse v and recombine
for (let r = 0; r < N; r++) {
for (let q = 0; q < N; q++) {
const i = idx(q, r);
if (isEdge(q, r)) { next[i] = BETA; continue; }
let sum = 0;
for (const [dq, dr] of NB) sum += v[idx(q + dq, r + dr)];
const avg = sum / 6;
const vNew = v[i] + (ALPHA / 2) * (avg - v[i]);
next[i] = u[i] + vNew;
}
}
// swap and freeze
const tmp = s; s = next; next = tmp;
for (let i = 0; i < N * N; i++) if (s[i] >= 1) frozen[i] = 1;
}








