void separate (float magnitude){
Vec3D steer = new Vec3D();
int count = 0;
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 30){
Vec3D diff = loc.sub(other.loc);
diff. normalizeTo(1.0/distance);
steer.addSelf(diff);
count++;
}
}
if(count > 0){
steer.scaleSelf(1.0/count);
}
steer.scaleSelf(4);
acc.addSelf(steer);
}
void lineBetween(){
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 90){
stroke(250);
strokeWeight(0.1);
line(loc.x,loc.y,other.loc.x,other.loc.y);
}
}
}
void move(){
speed.addSelf(acc);
speed.limit(2);
loc.addSelf(speed);
acc.clear();
}
void bounce() {
if(loc.x > width) {
speed.x = speed.x * -1;
}
if(loc.x < 0) {
speed.x = speed.x * -1;
}
if(loc.y > height) {
speed.y = speed.y * -1;
}
if(loc.y < 0) {
speed.y = speed.y * -1;
}
}
void display(){
fill(0);
stroke(0);
ellipse(loc.x,loc.y,5,5);
}
}