Programmatic guide for the @cazala/party library: engine setup, modules, particles, and performance across CPU + WebGPU.
npx playbooks add skill cazala/party --skill skill
Build a visible result first, then tune it. Treat a Party scene as four layers:
Use semantic enums and create particles before calling play():
import {
Behavior,
Boundary,
Engine,
Particles,
ParticlesColorType,
Spawner,
Trails,
} from "@cazala/party";
const canvas = document.querySelector<HTMLCanvasElement>("canvas")!;
const width = window.innerWidth;
const height = window.innerHeight;
const forces = [
new Boundary({ mode: "warp" }),
new Behavior({
wander: 18,
cohesion: 1.4,
alignment: 4,
separation: 35,
viewRadius: 80,
}),
];
const render = [
new Trails({ trailDecay: 8, trailDiffuse: 1 }),
new Particles({ colorType: ParticlesColorType.Hue, hue: 0.62 }),
];
const particles = new Spawner().initParticles({
count: 4_000,
shape: "donut",
center: { x: 0, y: 0 },
radius: Math.min(width, height) * 0.38,
innerRadius: Math.min(width, height) * 0.12,
size: 2.5,
mass: 1,
velocity: { speed: 120, direction: "clockwise" },
colors: ["#ffffff"],
});
const engine = new Engine({
canvas,
forces,
render,
runtime: "auto",
cellSize: 40,
maxNeighbors: 128,
});
await engine.initialize();
engine.setSize(width, height);
engine.setParticles(particles);
engine.addOscillator({
moduleName: "particles",
inputName: "hue",
min: 0,
max: 1,
speedHz: 0.01,
});
engine.play();
Copy [the full Vite starter](assets/starter/) when building a new app. It includes responsive sizing, pointer interaction, cleanup, and five selectable scenes. Read its [tested scene source](assets/starter/src/scenes.ts) when adapting a recipe.
| Intent | Start with |
| --- | --- |
| Falling, bouncing particles | Environment + Boundary; add Collisions if particles must hit each other |
| Orbital motion | Tangential Spawner velocity + inward Environment |
| Swarms and flocking | Behavior; add Trails for readable motion |
| Slime-mold filaments | Sensors + Trails + a warp Boundary |
| Liquid or viscous blobs | Fluids + Boundary; add gravity or pointer Interaction |
| Pointer fields | Interaction for attract/repel or Grab for one particle |
| Ropes and structures | Joints + Lines |
| Text/image dissolves | Text/image Spawner + outward velocity + Trails or Behavior |
Use the smallest combination that expresses the idea. Adding every module usually makes the motion harder to control.
Read [creative-workflow.md](references/creative-workflow.md) for parameter intuition and iteration guidance. Read [recipes.md](references/recipes.md) for five compositions derived from Party playground demos.
runtime: "auto" unless the user requires a specific runtime.getParticles() as an expensive full WebGPU-to-CPU readback. Never call it in an animation, pointer-move, or drag loop.await engine.getParticlesInRadius(...) for bounded local queries.setParticle(...) and setParticleMass(...) for local mutations.cellSize near the largest active neighborhood radius, and cap maxNeighbors deliberately.docs/module-author-guide.md only when authoring a new force or render module from a full Party checkout.await engine.destroy() during teardown.Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.