-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalker.js
More file actions
39 lines (34 loc) · 888 Bytes
/
walker.js
File metadata and controls
39 lines (34 loc) · 888 Bytes
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
class Walker extends Vector {
constructor(x, y, r) {
super(x, y);
this.radius = r;
this.twoRadius = r * 2;
}
walk() {
this.add(randomV());
this.constrain(new Vector(), createV(width, height));
}
watchStep(otherWalkers) {
for (let otherW of otherWalkers)
if (distanceV(this, otherW) <= this.radius + otherW.radius)
return true;
return false;
}
addColor(r, g, b) {
this.color = { r, g, b };
}
changeRadius(r) {
this.radius = r;
this.twoRadius = r * 2;
}
}
function createWalkerOnEdge(edge, radius) {
if (edge == 0) // top
return new Walker(random(width), 0, radius);
if (edge == 1) // right
return new Walker(width, random(height), radius);
if (edge == 2) // bottom
return new Walker(random(width), height, radius);
if (edge == 3) // left
return new Walker(0, random(height), radius);
}