align(boids) {

        let perceptionRadius = 50;
        let steering = createVector(); //desired direction
        let total = 0; //total number in the distance

        for (let other of boids) {
            //distance between thiss boid and other boids
            let d = dist(this.position.x, this.position.y, other.position.x, other.position.y);

            //as long as other is not me and distance <100
            if (other != this && d < perceptionRadius) {
                steering.add(other.velocity);
                //average the velocity of the boids around
                total++;
            }
        }

        if (total > 0) {
            steering.div(total);
            steering.setMag(this.maxSpeed);
            steering.sub(this.velocity);//speed - velocity = acceleration
            steering.limit(this.maxForce); //F = MA, we assume M is 1, so F = A
        }
        return steering; // return outside the function
    }
//figure out how individual boid detect the direction of other boids around it and reconfigure its own direction
figure out how individual boid detect the direction of other boids around it and reconfigure its own direction
figure out how individual boid detect the direction of other boids around it and reconfigure its own direction
align(boids) {
        let perceptionRadius = 50;
        let steering = createVector(); 
        let total = 0; 
        for (let other of boids) {
            let d = dist(this.position.x, this.position.y, other.position.x, other.position.y);
            if (other != this && d < perceptionRadius) {
                steering.add(other.velocity);
                total++;
            }
        }
        if (total > 0) {
            steering.div(total);
            steering.setMag(this.maxSpeed);
            steering.sub(this.velocity);
            steering.limit(this.maxForce); 
        }
        return steering; 
    }
align ( boids ) { let perceptionRadius = 50 ; let steering = createVector ( ) ; let total = 0 ; for ( let other of boids ) { let d = dist ( this . position . x , this . position . y , other . position . x , other . position . y ) ; if ( other != this && d < perceptionRadius ) { steering . add ( other . velocity ) ; total ++ ; } } if ( total > 0 ) { steering . div ( total ) ; steering . setMag ( this . maxSpeed ) ; steering . sub ( this . velocity ) ; steering . limit ( this . maxForce ) ; } return steering ; }
figure out how individual boid detect the direction of other boids around it and reconfigure its own direction
figure out how individual boid detect the direction of other boids around it and reconfigure its own direction
//desired direction //total number in the distance //distance between thiss boid and other boids //as long as other is not me and distance <100 //average the velocity of the boids around //speed - velocity = acceleration //F = MA, we assume M is 1, so F = A // return outside the function