octagons draws animated backgrounds built from regular octagons — octagon line art backgrounds on canvas, where the colour gradient runs along the edges and nothing is ever filled. Zero dependencies, about 3.1 KB gzipped.
Two modes
field— depth. Regular octagons scattered through depth, drifting toward the camera and overlapping at different scales. Because each one faces the viewer, it stays exactly regular at any distance; only its scale changes. Some carry a concentric inner ring, a few use the accent colour, and the field drifts with the pointer.lattice— the 4.8.8 tiling. A square lattice with every corner cut, so each cell becomes a regular octagon and each node a small square, with a soft band of light sweeping across the edges.nodesswaps the squares for small octagons, andbondrandomly fuses neighbouring octagons into one outline.
A regular octagon cannot tile the plane on its own, so the lattice is the truncated square tiling: cut every corner of a square grid and the cells become exactly regular. Drawing outlines instead of fills is what lets the leftover squares read as nodes rather than holes.
How to use it
Install with npm install octagons or load octagons.min.js from a CDN, then call:
Octagons.init('.bg', { mode: 'field' });
The script defines one global, Octagons, and the canvas fills the container you give it. The instance can set() options live, stop(), start(), step() one frame, resize() and destroy() itself.
Beyond the animation
- Static pattern. The lattice is periodic, so
pattern()returns a seamless lattice pattern for CSS — a repeating SVG ready to use as abackground-imageunder code blocks, cards or panels. Pick a pitch of 24 px or more if the octagon shape matters. - Offline rendering. A
seed, a transparent canvas andstep(dt)on your own clock give reproducible frames for video: two runs with the same seed produce byte-identical canvases. The README walks through screenshotting the frames and assembling them into a ProRes 4444 clip with an alpha channel. - Performance. The loop sleeps when the container is off screen or the tab is hidden, gradients are built once, glow avoids
shadowBlur, and the device pixel ratio is capped at 2. - A card deck. A sponsored extra in the package: 52 cards, two jokers and a back as static SVG, all drawn from the library's own geometry.
The family and licence
octagons is the 8 of a small family of zero-dependency polygon backgrounds: trigons-lite for triangles and hexagons-lite for honeycombs. MIT licence, built by 301ST for generator.ink.