trigons-lite draws lightweight animated triangulated backgrounds for the web: a low-poly background on canvas with fake directional lighting, or the same mesh as line art with a light sweep. Zero dependencies, about 3 KB gzipped.
Two modes
fill(default) — filled low-poly triangles with fake directional lighting from cross-product normals. A static painting: nothing runs between animations.lines— the same triangulated mesh drawn as strokes, with a soft light band sweeping diagonally across the edges. Its loop pauses automatically when the tab is hidden, andstop()pauses it by hand.
Entrance animation effects
Four effects — fade, scale, spin and fly — across six stagger directions: top, bottom, left, right, centre and random. animateIn() and animateOut() take a duration, a stagger spread, an easing and an onComplete callback, which is also how the README suggests switching between a dark and a light theme: animate out, re-initialise with the other colours, animate in.
How to use it
Install with npm install trigons-lite or load trigons-lite.min.js from a CDN, then call:
TrigonsLite.init('#bg', { colors: ['#0a0a0f', '#1a1a24', '#8e7cff'] });
The script exposes one global, TrigonsLite. Colours are two or three values in hex, rgb() or rgba() — or colorVars, the names of CSS custom properties to read from your site's design tokens.
Features
- Static pattern —
TrigonsLite.pattern()returns a seamless triangle pattern for CSS as aurl(...)value, with no canvas at all. - Deterministic mesh — pass
seedand the same triangles appear on every load, useful for visual regression tests; without it the mesh is random per instance but stable across resizes. - Sharp on retina — DPR-aware rendering, capped at
maxDpr. - Proper lifecycle —
destroy()removes the canvas and every listener. - Light on the browser — canvas rendering with no SVG DOM overhead, grid triangulation instead of Delaunay, and a debounced resize handler.
The family and licence
trigons-lite is the origin — the 3 — of a small family of zero-dependency polygon backgrounds, followed by hexagons-lite and octagons. It is inspired by the Trigons plugin by DeeThemes and rewritten from the ground up for a minimal footprint. MIT licence, built by 301ST.