Here is the first implementation, unfortunately it does not look as if it includes direction, but that it not necessary for fireflies! nevertheless I will look into it later.
/*
Boid coding
Joe Swann 2008
Reference:
Conrad Parker
http://www.vergenet.net/~conrad/boids/pseudocode.html
*/
1void setup(){
init_boid_pos(); //initial boid positions
}
void draw(){
draw_target(); // I want the boids to be targetting a moving object
draw_boids(); //draw the boids in this frame
move_boids(); //calculate the boid position for next frame
}
void move_boids(){
Vector [v1, v2, v3];
boid (b);
for (each boid){
v1 = rule1(b); //flock to center
v2 = rule2(b); //individual avoidance
v3 = rule3(b); //match velocity with near boids
v4 = rule4(b); //tendency to target
b.velocity = b.velocity + v1 + v2 + v3 +v4;
b.position = b.position + b.velocity;
}
}
void rule1(boid bx){ //attraction to center rule
vector pcx;
for each boid;
if (b! = bx) {
pcx = pcx + b.position;
}
}
pcx = pcx / (n-1);
return (pcx - bx.position / 100);
}
void rule2 (boid bx){ //avoidance rule
for each boid b
if (b! = bx) {
if |b.position - bx position| < c =" c" pvx =" pvx" pvx =" pvx/n-1">
Labels:
Input Device,
Semester 2
Subscribe to:
Post Comments (Atom)
0 comments: