Creative Coding From Zero · Episode 08
Generative Poster
Generative Poster is Episode 08 of Creative Coding From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.
Part of the MasterAllArts Creative 3D Roadmap .
Seven episodes ago you couldn't move a single pixel on purpose. Now you have a whole toolbox: a seeded random generator that makes chaos repeatable, value noise that makes chaos smooth, flow fields that turn that noise into rivers of ink, particle systems that swarm, and cosine palettes that keep color from turning to mud. This finale wires all of it together into one machine. Press a button, get a poster — a balanced, composed, frame-worthy image you'd actually print and hang.
The promise of this episode is specific and a little audacious: one click = one poster, and every poster is different, composed (a focal point, real negative space, margins), and reproducible — type the same seed tomorrow on another machine and you get pixel-for-pixel the same artwork. Then hit SAVE PNG and it's a file. That last property is what separates a generative toy from a generative tool: the seed is the whole artwork, compressed to one integer. Build the demo below, then we'll take it apart layer by layer.
Tip: change stage to watch the poster build up in layers — wash, then ink,
then accents, then harmonized color, then composition + grain. The dice picks a new
seed; the thumbnails are a live gallery you can click to load.
What you're looking at
Everything in that frame is a pure function of the number in the seed
box. There is no Math.random() anywhere in the art — the seed feeds a
mulberry32 generator, which seeds a noise field, which steers a flow field,
which scatters accents, all colored through one cosine palette and finished with film
grain. Change the seed and the entire composition reorganizes: new horizon, new ink
currents, new focal mark, new color story. Type the seed back and it returns exactly.
Two things make it feel like a poster rather than noise. First, negative space: the generator deliberately leaves quiet regions and a clean margin so the eye has somewhere to rest. Second, a focal point — one dominant mark placed off-center (near a rule-of-thirds intersection) that the composition is built around. Those two rules are the difference between "a screensaver" and "a thing you'd frame," and they're the real lesson of the finale.
The whole poster is composed once per seed, not once per frame. A poster is a still image; redrawing fifty thousand ink steps sixty times a second would melt your laptop for no benefit. So we render to an offscreen buffer when the seed changes and just blit that buffer each frame — leaving a tiny, cheap animated shimmer on top so the demo is alive without being wasteful.
Stage 1 — Background wash
Every poster needs a ground to stand on. The wash is low-frequency
fbm noise mapped through the palette: a soft, cloudy gradient that already
has a sense of light and direction (a faint "horizon"), but no detail yet. This is the
single most important layer for mood — warm vs cool, calm vs stormy — and the
cheapest to compute. Get the wash right and everything stacked on top inherits its
atmosphere. Slide complexity and watch the cloud structure tighten.
Stage 2 — Flow-field ink
Now the season's signature move. We drop a few hundred "ink" particles onto the canvas and let a flow field — the gradient of a second noise function — carry each one across the frame, leaving a faint translucent trail. Hundreds of trails accumulate into coherent rivers and eddies because neighboring particles feel nearly the same field. This is the layer that reads as gesture and hand; it's why the poster looks drawn rather than rendered. Note we never clear between ink steps — persistence is the whole point.
Stage 3 — Shape accents
Rivers alone are too even. Accents break the rhythm: a seeded scatter of focal marks — discs, rings, thin lines, little arcs — placed with intent rather than uniformly. They cluster loosely around the focal point and thin out toward the margins, which is what gives the composition a center of gravity. Each accent's position, size, and kind is drawn from the seed, so the scatter is fixed for a given poster but wildly different across seeds.
Stage 4 — One palette, everywhere
Here's the harmony trick. Instead of picking colors per layer (a fast road to mud),
every layer samples the same cosine palette — wash, ink, and
accents all draw from one continuous ramp, just at different positions along it. Because
Inigo Quilez cosine palettes are smooth loops of related hues, anything you pull from
them already belongs together. The palette dropdown swaps the ramp; "auto"
derives a fresh, tasteful ramp from the seed itself, so the color story is part of what
the seed encodes.
Stage 5 — Composition + grain
The finishing layer is about restraint, not addition. We carve out negative
space, paint a clean inner margin (a quiet border frames the work), nudge contrast
around the focal point so the eye lands there first, and lay a film-grain overlay over
the whole thing for tactility — the faint tooth that makes a flat digital image read
like print. Grain is seasoning: a touch adds warmth, too much just looks noisy. The
grain slider lets you taste it.
Stage 6 — The generator
All five layers, on demand. Type a seed or roll the dice and the full pipeline runs
once: seed → wash → ink → accents → palette → composition → grain. The
result is a finished poster, reproducible forever from that one integer. Hit
SAVE PNG to download it as poster-<seed>.png — the
filename carries the seed, so your export is self-documenting. The little strip of
thumbnails along the bottom is a live gallery of recent seeds; click any one to load it
full-size. This is the whole season, in one button.
How the code works
We need all three shared helpers this time — mulberry32,
makeNoise/fbm, and cosPalette. They're the spine
of the series; here they finally play together. The single most important idea in the
whole file is this: the artwork is a pure function of the seed. One
integer in, one specific poster out, every time.
(a) The seed → piece pipeline
A Piece is just a bundle of parameters derived from the seed:
the palette ramp, the noise instances, where the horizon sits, where the focal point
lands, how many ink particles and accents to spawn. Notice every value is pulled from
one rnd() stream — that's what makes a seed reproduce. Build the parameters
first, draw second.
// ONE integer in → one fully-specified poster out.
function makePiece(seed, opts) {
const rnd = mulberry32(seed); // every choice below flows from this
const noiseA = makeNoise(seed); // wash / atmosphere
const noiseB = makeNoise(seed ^ 0x9e37); // flow field (a different field)
// rule-of-thirds focal point, jittered off the exact intersection
const fx = (rnd() < 0.5 ? 0.33 : 0.66) + (rnd() - 0.5) * 0.12;
const fy = (rnd() < 0.5 ? 0.34 : 0.64) + (rnd() - 0.5) * 0.12;
return {
seed, rnd, noiseA, noiseB,
pal: pickPalette(seed, opts.palette), // the one ramp (stage 4)
horizon: 0.30 + rnd() * 0.40, // where the wash splits
focal: { x: fx, y: fy },
inkCount: (260 * opts.complexity) | 0, // flow particles (stage 2)
accents: (14 * opts.complexity) | 0, // focal marks (stage 3)
angle: rnd() * 6.2832, // global ink bias
grain: opts.grain,
};
}
Everything downstream reads from this object. Want a variation? Change the seed. Want the same poster at a different size? Pass the same seed to a bigger canvas (that's the 2× print export exercise). The piece is the contract.
(b) The layered compose()
Order is not optional. The wash must go down before the ink, the ink before the
accents, the grain dead last (it sits on everything, including the margins).
Each layer is its own function; compose() just calls them in the one
correct sequence into an offscreen buffer:
// Draw the whole poster ONCE into an offscreen buffer (not per frame!).
function compose(piece, g, W, H) {
drawWash(piece, g, W, H); // 1. ground / atmosphere
drawFlowInk(piece, g, W, H); // 2. accumulated ribbons over the wash
drawAccents(piece, g, W, H); // 3. focal marks on top of the ink
drawComposition(piece, g, W, H); // 4. focal contrast + clean margin
drawGrain(piece, g, W, H); // 5. film grain over the entire frame
}
// stages 1–5 just stop the pipeline early, so each stage is "compose up to N":
const steps = [drawWash, drawFlowInk, drawAccents, drawComposition, drawGrain];
function composeUpTo(piece, g, W, H, n) {
for (let i = 0; i <= n; i++) steps[i](piece, g, W, H);
}
The flow-ink layer is the season's flow field, condensed. Each particle reads the noise field for an angle, steps along it, and stamps a faint dab — and crucially we don't clear between steps, so the dabs pile into rivers:
function drawFlowInk(p, g, W, H) {
const { rnd, noiseB, pal } = p;
for (let i = 0; i < p.inkCount; i++) {
let x = rnd() * W, y = rnd() * H; // seeded start
const col = cosPalette(rnd(), ...pal); // same ramp as everything
g.strokeStyle = col; g.globalAlpha = 0.06; // faint → trails accumulate
g.beginPath(); g.moveTo(x, y);
for (let s = 0; s < 90; s++) { // march along the field
const a = noiseB(x * 0.0016, y * 0.0016) * 6.2832 + p.angle;
x += Math.cos(a) * 2.2; y += Math.sin(a) * 2.2;
g.lineTo(x, y);
}
g.stroke();
}
g.globalAlpha = 1;
}
(c) Picking and applying one palette across every layer
Harmony comes from discipline: one ramp, sampled everywhere. A cosine
palette is four RGB triplets (a,b,c,d); "auto" derives a fresh set from the
seed so the color story is part of the seed's identity. Every drawX
function calls cosPalette(t, ...piece.pal) for its colors — they cannot
clash because they're all points on the same loop:
const PRESETS = [
/* ember */ [[.5,.4,.3],[.5,.4,.3],[1,1,.6],[.0,.12,.20]],
/* tide */ [[.3,.4,.5],[.4,.4,.4],[1,1,1],[.55,.62,.70]],
/* orchid */ [[.5,.3,.5],[.5,.4,.4],[1,1,1],[.30,.20,.55]],
/* forest */ [[.3,.45,.35],[.4,.3,.3],[1,1,.8],[.20,.40,.18]],
/* mono */ [[.5,.5,.5],[.45,.45,.45],[1,1,1],[.0,.0,.0]],
];
function pickPalette(seed, choice) {
if (choice > 0) return PRESETS[choice - 1]; // user forced a preset
const r = mulberry32(seed ^ 0x5151); // auto: derive from seed
const d = [r(), r(), r()]; // random phase = the hue story
return [[.5,.5,.5], [.5,.5,.5], [1,1,1], d]; // QZ default a,b,c + seeded d
}
(d) Save the poster as a PNG
The export is three lines: ask the canvas for a PNG data URL, hang it on a temporary
<a download>, and click it. We bake the seed into the filename so an
exported poster always carries the recipe that made it:
function savePNG(canvas, seed) {
const url = canvas.toDataURL('image/png'); // snapshot the pixels
const a = document.createElement('a');
a.href = url;
a.download = `poster-${seed}.png`; // self-documenting filename
a.click(); // triggers the browser download
}
saveBtn.addEventListener('click', () => savePNG(canvas, current.seed));
Because the poster is composed into a full-resolution offscreen buffer, the PNG is crisp regardless of how small the demo is on the page — and bumping that buffer to 2× (the print exercise) gives you a genuinely hangable file with no other code changes.
Common pitfalls
- Filling every pixel. The rookie generative mistake is treating empty space as wasted space. It isn't — negative space is what makes the busy parts read. Reserve quiet regions and a margin on purpose; a poster that's loud everywhere is loud nowhere.
- No focal point. A balanced-but-uniform field is boring. Give the eye one place to land first (here: an off-center mark near a rule-of-thirds line) and build contrast around it. Composition is hierarchy, not symmetry.
- Layer order. Grain under the ink, or accents under the wash, and
the whole thing looks wrong in a way that's hard to name. The sequence
wash → ink → accents → composition → grainis load-bearing — grain in particular must be last so it sits over everything. - Composing every frame. A poster is a still. Drawing tens of thousands of ink steps 60×/second tanks fps for zero visual gain. Compose once into an offscreen buffer when the seed changes, blit it each frame, and animate only something cheap on top (a faint shimmer).
- Leaking randomness. A single stray
Math.random()— in the grain, in an accent, anywhere — and the seed no longer reproduces the poster. Route all randomness through the seededrnd(). Reproducibility is a property you either have completely or not at all. - Grain too strong. Heavy grain reads as a broken JPEG, not as film. Keep it subtle (alpha well under ~0.2) and let it flavor the image rather than dominate it.
Exercises
- A 3×3 seed gallery. Render nine thumbnails from nine seeds at once (the demo already shows a small strip — make it a full grid). Compose each into a tiny offscreen canvas and lay them out. Clicking a tile loads that seed full-size. This is how real generative artists "shop" for the keeper among hundreds of rolls.
- Sign your work. Add a title and a small signature in a corner — set in the monospace stack, kept inside the margin, drawn after the grain so it stays crisp. Real posters have a typographic anchor; one line of text turns an abstract field into a piece with intent.
- Export at 2× for print. Make a "save at 2×" button that composes
the same seed into a buffer twice the size, then
toDataURLs that. Because the whole piece is a pure function of the seed, you get a higher-res version of the identical poster — suitable for an actual print. (Watch for GPU canvas size limits on very large exports.)
What's next
That's a wrap on Season 1 — The Canvas & Motion. You started by
learning the difference between clearRect and a trail, and you finish able
to generate frame-worthy, reproducible posters on demand. Every tool in this finale —
seeded randomness, noise, flow, particles, palettes, composition — was a previous
episode. The poster was just the excuse to make them sing together.
Season 2 — Simulation & Systems turns the camera around: instead of drawing a system, you'll grow one and watch it surprise you. Flocking (boids — thousands of agents, three rules, emergent murmurations), cellular automata (Conway's Life and beyond — complexity from a grid of on/off cells), and reaction–diffusion (two chemicals, one feedback loop, and the spots-and-stripes patterns of the living world). Same raw canvas, zero dependencies — but now the art moves on its own. See you there.