createParticleFlow(canvas, options)
Creates one real-time particle field and returns ParticleFlowController.
createParticleFlow(
canvas: HTMLCanvasElement | string,
options?: ParticleFlowOptions,
): ParticleFlowControllerParticle options
| Field | Type | Default |
|---|---|---|
mode |
ParticleMode | ParticleField |
"pulse" |
density |
number |
1 |
speed |
number |
1 |
size |
number |
1 |
radius |
number |
0.39 |
depth |
number |
0.9 |
perspective |
number |
3.2 |
seed |
number |
11 |
colors |
string[] |
three-color neutral palette |
background |
string | null |
null |
shape |
ParticleShape |
"circle" |
shapeOptions |
ParticleShapeOptions |
configurable fill, sides, rotation and aspect |
lineLength |
number |
5 |
lineWidth |
number |
0.7 |
blendMode |
GlobalCompositeOperation |
"source-over" |
trail |
number |
0 |
jitter |
number |
0 |
opacity |
[far, near] |
[0.2, 0.96] |
rotation |
{ x?, y?, z? } |
{ x: -0.18, y: 0, z: 0 } |
scale |
{ x?, y?, z? } |
{ x: 1, y: 1, z: 1 } |
origin |
{ x?, y? } |
{ x: 0.5, y: 0.5 } |
viewport |
{ padding?, clip? } |
{ padding: 0, clip: true } |
particles |
"auto" | number | ParticleCountOptions |
"auto" |
parameters |
Record<string, number> |
standard field parameters |
interaction |
boolean | ParticleInteractionOptions |
rotate |
connections |
"auto" | boolean | ParticleConnectionsOptions |
"auto" |
transform |
ParticleTransform | ParticleTransform[] | null |
none |
renderer |
ParticleRenderer |
built-in painter |
beforeRender |
ParticleFrameHook | null |
none |
afterRender |
ParticleFrameHook | null |
none |
pixelRatio |
number | "auto" |
"auto" |
autoPause |
boolean |
true |
autoplay |
boolean |
true |
reducedMotion |
"respect" | "ignore" |
"respect" |
ParticleMode includes pulse, orbit, orb, wave, helix, vortex, constellation, scatter, lattice, ribbon, tunnel, stream, torus, rose, swarm, grid-wave, burst, and infinity.
ParticleShape includes circle, square, diamond, triangle, line, cross, ring, dash, star, and polygon.
Shape options
interface ParticleShapeOptions {
rotation?: number;
sides?: number; // 3-12 for polygon
fill?: boolean;
strokeWidth?: number;
aspect?: number;
}Pointer interaction
interface ParticleInteractionOptions {
mode?: "rotate" | "repel" | "attract";
strength?: number;
radius?: number;
smoothing?: number;
}Connections
interface ParticleConnectionsOptions {
distance?: number;
opacity?: number;
width?: number;
color?: string;
maxPoints?: number;
}Particle field
type ParticleField = (context: {
index: number;
count: number;
time: number;
seed: number;
parameters?: Readonly<Record<string, number>>;
}) => ParticlePoint;ParticlePoint contains x, y, and z, plus optional size, opacity, numeric color index and rotation values.
Particle controller
interface ParticleFlowController {
readonly canvas: HTMLCanvasElement;
readonly playing: boolean;
play(): void;
pause(): void;
render(time?: number): void;
resize(): void;
update(options: Partial<ParticleFlowOptions>): void;
destroy(): void;
}Particle utilities
particleFieldsexposes the eighteen built-in field functions.particlePresetsaddsorbitMesh,petals,current,terrain,flare, andloopto the original presets.sampleParticleField(mode, context)samples a built-in or custom field without creating a canvas engine.mixParticleFields(from, to, amount)returns a field that interpolates two topologies.composeParticleTransforms(...transforms)builds a reusable sequential transform.particleTransformsprovidesscale(),twist(),ripple(), andlimit()factories.
Transforms may return false to remove a point from the current frame. Custom renderers receive screenX, screenY, renderSize, and colorValue on the projected point.
flow(target, options)
Animates every resolved target and returns FlowControls.
flow(target: FlowTarget, options?: FlowOptions): FlowControlsTargets
type FlowTarget =
| string
| Element
| Iterable<Element>
| ArrayLike<Element>;Options
| Field | Type | Default |
|---|---|---|
preset |
PresetName | FlowPreset |
none |
from |
FlowFrame |
{} |
to |
FlowFrame |
{} |
keyframes |
FlowFrame[] |
generated from from and to |
duration |
number |
preset or 600 |
stagger |
number | (index, total) => number |
0 |
pixel |
boolean | { steps?, snap? } |
preset or false |
autoplay |
boolean |
true |
reducedMotion |
"respect" | "ignore" |
"respect" |
Standard KeyframeAnimationOptions values are accepted too.
Transform shortcuts
FlowFrame supports native keyframe properties plus these typed shortcuts:
{
x, y, z,
scale, scaleX, scaleY,
rotate, rotateX, rotateY,
skewX, skewY,
blur
}Numeric translate and blur values use pixels. Numeric rotation and skew values use degrees. String values keep their unit.
createFlow(defaults)
Returns a scoped flow function with reusable defaults.
const brandFlow = createFlow({ duration: 700, fill: "both" });
brandFlow(".item", { preset: "smooth-rise" });stagger(amount, options)
Returns a delay resolver. from accepts "first", "center", or "last". start adds an initial delay. ease transforms normalized distance.
timeline(steps, options)
Schedules several flows and returns one controller. See Timelines and control.
inView(target, animation, observerOptions)
Starts a flow when targets intersect. observerOptions accepts normal IntersectionObserverInit fields plus once.
Easing helpers
pixelEase(steps?: number, position?: "start" | "end"): string
spring(options?: SpringOptions): stringThe easings object exports linear, out, inOut, snap, and spring values.
Presets
type PresetName =
| "pixel-pop"
| "pixel-slide-up"
| "pixel-glitch"
| "pixel-flip"
| "smooth-rise"
| "smooth-scale"
| "smooth-blur-in"
| "smooth-slide-left"
| "smooth-slide-right"
| "soft-spring"
| "elastic-pop";Use definePreset() for typed custom preset objects.