integrator

The update step of an agent simulation: one per kind of agent.

integrator: { forces3d, steering2d, orientation2d, drift2d, relief, advect2d }

Import sim from shaders/std and use sim.agentForces.integrator.

Each takes your layout and the parts, and returns the step to register as update in bake.

forces3d moves a 3D swarm under summed forces with drag and a speed limit. steering2d moves a flock that keeps cruising and arcs off the edges. orientation2d turns agents in place under summed torques. drift2d glides motes and wraps them around the canvas. relief stands particles on the child's image. advect2d carries particles along a fluid.

Example

const update = integrator.forces3d(simLayout, {forces: [pressure.force, force.containment(simLayout, containmentCfg), force.cursorXY(simLayout), force.gravity(simLayout)], maxSpeed: 3, posClamp: 1.9, name: 'swarmUpdate'})

Tip. Drag arrives as a per-frame multiplier in params.dragMul. Compute it with agentFrame.expDecay(rate, dt) so it does not depend on frame rate.

Members

  • integrator.forces3d — A 3D swarm under summed forces, with drag, a speed limit and a position clamp.
  • integrator.steering2d — A flock under summed steering, kept cruising, arcing off the canvas edges.
  • integrator.orientation2d — Agents that turn in place under summed torques and drift a little toward the field.
  • integrator.drift2d — Motes that glide on a built-in drift plus a fading gust, wrapping around the canvas.
  • integrator.relief — Particles standing on the child's image, rising by a color channel, springing home.
  • integrator.advect2d — Particles carried by a fluid's velocity texture, easing back to an even spread.

See also

  • force — The pushes an agent can feel.
  • torque — The turns an agent that spins in place can feel, for integrator.orientation2d.
  • drift — A built-in velocity for motes that glide, for integrator.drift2d.
  • field — What a turning agent samples at its position: the magnetic field at the cursor, and its resting place on a jittered grid.
  • renderAgents — How the agents are drawn, as one declared part: a splat (each agent stamps its shape into a shared canvas) paired with the matching resolve (the canvas becomes the output picture).
  • agentSim — A simulation of many agents, spread into a definition: bake assembles the steps from your declared parts, frame writes the per-frame values, and the fragment samples the picture.