API reference
createField & options
The lowest-level entry point. createField(canvas, options) starts the engine on
a canvas you provide and returns the FieldHandle. The web
component, the FieldField class, and mountField() all wrap it.
Signature
TypeScript
import { createField } from 'field-ui';
const field = createField(canvas, options); // → FieldHandle FieldOptions
Every field is optional. Defaults keep the live field unchanged until you opt in.
-
accentstring · default palette's first stop - The travelling accent colour (a hex string).
-
densitynumber · default 1 - Particle-count multiplier.
-
wavesboolean · default true - Draw the background Currents (the wave layers).
-
render'dots' | 'trails' | 'links' | 'metaballs' | 'voronoi' | 'streamlines' · default 'dots' - Render mode — the same physics drawn differently.
-
massboolean · default false - First-class mass: particle mass ∝ size and body forces accelerate by a = F/m.
-
palettestring | string[] · default 'ours' - Accent template — a built-in name or custom hex stops.
-
attentionboolean · default false - Conserved attention — one finite strength budget; engaging a body starves the others.
-
causalityboolean · default false - Cross-boundary causality — a saturated body spills density to its neighbours.
-
heatmapboolean · default false - Density heatmap — a glow layer of where matter pools, sampled back to bodies as --forces-heatmap-density.
Common configurations
Every option is optional and the defaults keep the field calm. These are the combinations
worth knowing — each is the whole options object. Switch tabs to compare.
// the resting field — an accent and a palette, nothing else
createField(canvas, { accent: '#4da3ff', palette: 'ours' }); // draw the force field itself as arrows — a diagnostic view
createField(canvas, { render: 'streamlines' }); // focus one thing at a time — one finite strength budget,
// so engaging a body starves the others
createField(canvas, { attention: true }); // a large or low-power surface — half the particles, no wave layer
createField(canvas, { density: 0.5, waves: false }); // first-class mass — particle mass ∝ size, bodies accelerate by a = F/m
createField(canvas, { mass: true }); These are creation-time. Most have a live counterpart on the
FieldHandle —
setPalette, setRender,
setAttention, setCausality — so you can change them after mount too.