Headstuff build log - WordPad
✕
C:\ar9av\builds\HEADSTUF.TXT
  1. Desktop
  2. Build Log
  3. Simulations & Toys

Build log · Simulations & Toys

How I built Headstuff

A pixel-art monster generator where every creature comes from one seed number

Screenshot of Headstuff running in the portfolio
Headstuff, running on the desktop. Open it yourself →

1.Why I built it

The first version of Headstuff was an iframe around headdds.alxxvine.com, a site that generates a creature from a number. That meant their watermark sat in the corner and none of the work was mine. There were no assets to borrow either, since that site generates everything, so the same day I replaced the iframe with my own generator.

The rule I kept is that a monster is a number. Nothing is stored or shipped as an image. The same seed always gives the same creature, so a monster can travel as an integer.

2.How it works

Grow half a silhouette, then mirror it

A monster is a 29x30 Uint8Array of part codes: body, belly, accent, sclera, pupil, mouth, tooth and spot. The width is odd so there is a true centre column to mirror about. Everything is painted on the left half and copied to the right with a putSym helper. Symmetry is what makes random pixels read as a creature.

The silhouette is built one row at a time. Each row's half-width follows an ellipse around a random waist height, plus a damped random walk for lumpiness. It is then smoothed twice with a 1-2-1 kernel to remove single-row spikes, and the top four rows are capped to a dome. Early profiles that only tapered one way looked like funnels, and the ellipse is what makes the body close at both the top and the bottom.

Features sized to the body they land on

Eyes are placed on a row near the top, and their size comes from the head's half-width at that row (eyeHalf / 3.5, capped at 3), because a one-cell eye on a wide head looks like a pinprick. Sclera is only painted on cells that are already body, so an eye can never hang off the edge of the silhouette. The generator also picks cyclops or stacked eyes, one of four mouth types, horns, antennae, ears or a spike, optional arms, and feet.

Spots are placed in 2x2 clusters instead of single cells, which would look like dirt. The belly is a rounded ellipse patch, since tapering it made it look like a bib.

Seeds, words and palettes

Randomness comes from mulberry32, a tiny seeded PRNG, so generate(seed) is deterministic. The name field hashes a lowercased word with FNV-1a into a seed between 0 and 9,999,999. The strip of thumbnails shows neighbouring seeds spaced by the prime 7919, so browsing it feels like moving through a space instead of rolling dice again.

The palette starts from one random hue. The accent colour is that hue plus 140 to 220 degrees, close to a complement, instead of a second unrelated hue that would make the result look muddy. Lit and shaded body tones are derived from the base by nudging hue and lightness.

Drawing it as pixel art

The renderer first fills every empty cell that touches the creature, including diagonals, with the outline colour, then draws the body blocks on top. That gives an outline exactly one cell thick. Body cells with empty space above use the lit tone and cells with empty space below use the shade tone, which gives a cheap rim light.

The cell size is always a whole number of device pixels, chosen to fit the window, and smoothing is turned off, so the blocks never land on half pixels and blur. PNG export renders the seed again to a separate canvas at 16 pixels per cell.

Animating the grid, not the canvas

The idle animation is a pose() function that returns a new grid each frame. A breath shifts every row above the feet down one cell while the feet stay put, horns and antennae lean one cell left or right on a slow sine, and a blink about every 3.6 seconds turns eye cells into body and leaves a lid line through the middle of each eye column. Each monster gets its own phase from the seed so they don't all blink together.

Moving cells instead of translating the drawn image keeps the outline correct and keeps everything on the pixel grid, since half-cell sliding stops it looking like pixel art. With prefers-reduced-motion set, it draws a single still frame.

3.Try it

Press New monster, type a seed, or type a word to hash it into a seed; click the thumbnails to browse nearby seeds and Save PNG to export.

More from the build log

Headstuff · 3 min readAll 29 builds