UNPKG

@thi.ng/boids

Version:

n-dimensional boids simulation with modular behavior system

19 lines (18 loc) 411 B
const blendedBehaviorUpdate = (boid) => { const { api: { maddN, setN }, behaviors, force } = boid; setN(force, 0); let i, n, weight, behavior; for (i = 0, n = behaviors.length; i < n; i++) { behavior = behaviors[i]; weight = behavior.weight(boid); if (weight !== 0) maddN(force, behavior.update(boid), weight, force); } return force; }; export { blendedBehaviorUpdate };