boids
Flock simulation and boids
Flock simulation with canvas, gl-vec2 and typescript.
Code is not optimized but slavishly ported from Nature of Code (chapter 6). Go Daniel Shiffman, go!
For the original code see here:
- https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp06_agents/NOC_6_09_Flocking
- https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp06_agents/NOC_6_02_Arrive
For a - maybe better, less OOP, more optimized - boid package see hughsk boid
Example
const flock = let target: vec2 = null for let i = 0; i < 60; i++ const opts = center: 0 0 canvasSize: canvasWidth canvasHeight velocity: Math Math r: 3 maxspeed: 3 maxforce: 005 separationScale: 15 alignScale: 10 cohesionScale: 10 desiredSeparation: 25 neighborDistance: 50 let b = opts flock { flock context for let i = 0; i < flockboidslength; ++i const boid = flockboidsi const x = boidposition0 const y = boidposition1 const theta = + MathPI / 2 context context context context context context context context context context }
License
MIT © nkint