separation(boids) {

        let perceptionRadius = 50;//how big the flock you want it to be smaller number more tiny flocks 
        let steering = createVector(); //desired direction
        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) {
                let diff = p5.Vector.sub(this.position, other.position);
                diff.div(d); //divide by distance or div(d)
                steering.add(diff);
                //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
    }
// add separation so they dont all converge to one spot
add separation so they dont all converge to one spot
add separation so they dont all converge to one spot
separation(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) {
                let diff = p5.Vector.sub(this.position, other.position);
                diff.div(d); 
                steering.add(diff);
                total++;
            }
        }
        if (total > 0) {
            steering.div(total);
            steering.setMag(this.maxSpeed);
            steering.sub(this.velocity);
            steering.limit(this.maxForce); 
        }
        return steering; 
    }
separation ( 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 ) { let diff = p5 . Vector . sub ( this . position , other . position ) ; diff . div ( d ) ; steering . add ( diff ) ; total ++ ; } } if ( total > 0 ) { steering . div ( total ) ; steering . setMag ( this . maxSpeed ) ; steering . sub ( this . velocity ) ; steering . limit ( this . maxForce ) ; } return steering ; }
add separation so they dont all converge to one spot
add separation so they dont all converge to one spot
//how big the flock you want it to be smaller number more tiny flocks  //desired direction //divide by distance or div(d) //average the velocity of the boids around //speed - velocity = acceleration //F = MA, we assume M is 1, so F = A // return outside the function