@thi.ng/boids
Version:
n-dimensional boids simulation with modular behavior system
13 lines (12 loc) • 322 B
JavaScript
const blendedBehaviorUpdate = (boid) => {
const { maddN, zeroes } = boid.api;
const force = zeroes();
for (let behavior of boid.behaviors) {
const weight = behavior.weight(boid);
if (weight !== 0) maddN(force, behavior.update(boid), weight, force);
}
return force;
};
export {
blendedBehaviorUpdate
};