-
Notifications
You must be signed in to change notification settings - Fork 1
/
birds.js
45 lines (45 loc) · 897 Bytes
/
birds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Bird extends Boid{
constructor(){
super();
this.maxForce = 0.1;
this.maxSpeed = 5 ;
}
show(){
let theta = this.velocity.heading() + PI/2;
let r = 3;
fill('white');
noStroke();
push();
translate(this.location.x,this.location.y);
rotate(theta);
beginShape();
vertex(0, -r*2);
vertex(-r, r*2);
vertex(r, r*2);
endShape(CLOSE);
pop();
}
}
class BirdPred extends Bird{
constructor(){
super();
this.maxForce = 0.2;
this.maxSpeed = 3;
this.id = 'predator';
}
show(){
let theta = this.velocity.heading() + PI/2;
let r = 5;
fill('red');
noStroke()
push();
translate(this.location.x,this.location.y);
rotate(theta);
beginShape();
vertex(0, -r*2);
vertex(-r, r*2);
vertex(r, r*2);
endShape(CLOSE);
pop();
}
}