-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboid.js
38 lines (35 loc) · 937 Bytes
/
boid.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
class Boid {
constructor(type, posx, posy, velx, vely) {
this.type=type;
this.pos=createVector(posx, posy);
this.vel=createVector(velx, vely);
this.cooldown=0; // for no re-bounces
}
updatePos() {
this.pos.add(this.vel);
if (this.pos.x<0 || this.pos.x>width) {
this.vel.x*=-1;
}
if (this.pos.y<0 || this.pos.y>height) {
this.vel.y*=-1;
}
this.cooldown--;
}
setType(newType) {
this.type=newType;
}
display() {
// fill(colourKey[this.type]);
// circle(this.pos.x, this.pos.y, diam);
if (this.type=='r') {
let mult=diam/rck.height
image(rck, this.pos.x, this.pos.y, mult*rck.width, diam);
} else if (this.type=='p') {
let mult=diam/ppr.height
image(ppr, this.pos.x, this.pos.y, mult*ppr.width, diam);
} else {
let mult=diam/scs.height
image(scs, this.pos.x, this.pos.y, mult*scs.width, diam);
}
}
}