particles
Thousands of moving points drawn into a texture, read by name in WGSL.
particles(opts: Parameters<typeof particlesInput>[0]): ParticlesInput
Import simulate from shaders/std and use simulate.particles.
count(number or prop) up tomax;mobile: {max}caps it on phones. -forces: data, e.g.[{gravity: 0.3}, {drag: 0.5}, {cursor: 1}, {wind: 0.4}]. Every strength (andradius,scale) takes a number or a prop,{spring: p('pull')}, read live, so sliders drive the physics. Forces:gravity,drag(settling),spring(back to the spawn point),cursor(pushed from the pointer while one is over the canvas),wander(each particle jiggles on its own),wind(a shared flow),vortex,orbit,separate. -spawn:'scatter'(default),'ring','edge','atPointer',{fromShape: source}(a texture's opaque area, e.g.samplePointsor a layer prop), or a WGSL body returning aParticle(it seesindexandrand: vec4f). -step: WGSL run per particle per frame withvar p: Particlein scope (andindex,rand). Forces are applied before it; position integrates after it. -lifetime: {seconds, jitter}respawns particles as they age out. -draw: WGSL returningPoint(pos, sizePx, color)per particle (it seespandindex). Without a state (no spawn, step or forces) it sees onlyindex: the formula-driven mode. -splat:'point'(1 px) or'soft'(a round footprintsizepixels wide). -neighbors: {radius}letsstepreadcrowd(p)andcrowdSlope(p): how crowded a spot is.
Parameters
| Name | Type | Notes |
|---|---|---|
opts | Parameters<typeof particlesInput>[0] |
Example
inputs: {
motes: simulate.particles({count: 20000, forces: [{wind: 0.4}, {cursor: 1}, {drag: 0.6}], lifetime: {seconds: 6, jitter: 0.5}, splat: 'soft'}),
},
paint: wgsl`return motes(uv);`,