boids/scripts/boid.js
/**
   * Find the average heading of the boids in this boid's view
   * @param {*} boidsInView
   */
Find the average heading of the boids in this boid's view
@param {*} boidsInView
Find the average heading of the boids in this boid ' s view @param { * } boidsInView
align(boidsInView) {
    let steering = boidsInView.reduce((sum, otherBoid) => {
      sum.add(otherBoid.vel);
      return sum;
    }, createVector()); 
    if (boidsInView.length > 0) {
      steering.div(boidsInView.length);
       Reset the speed
      steering.setMag(maxSpeed);
       desiredVel - currentVel = steeringForce
      steering.sub(this.vel);
       Cap the magnitude of the average velocity
      steering.limit(maxForce);
    }
    return steering;
  }
align ( boidsInView ) { let steering = boidsInView . reduce ( ( sum , otherBoid ) => { sum . add ( otherBoid . vel ) ; return sum ; } , createVector ( ) ) ; if ( boidsInView . length > 0 ) { steering . div ( boidsInView . length ) ; steering . setMag ( maxSpeed ) ; steering . sub ( this . vel ) ; steering . limit ( maxForce ) ; } return steering ; }
Find the average heading of the boids in this boid's view
 @param {*} boidsInView
Find the average heading of the boids in this boid ' s view @param { * } boidsInView
// Find the average heading of the near boids // Initial value for steering // // Reset the speed // desiredVel - currentVel = steeringForce // Cap the magnitude of the average velocity