-
Notifications
You must be signed in to change notification settings - Fork 1
/
Agent.js
32 lines (29 loc) · 1.31 KB
/
Agent.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
var Agent = function() {
this.vector = myp5.createVector(myp5.random(myp5.width), myp5.random(myp5.height));
this.vectorOld = this.vector.copy();
this.stepSize = myp5.random(1, 5);
this.isOutside = false;
this.angle;
};
Agent.prototype.update = function(strokeWidth) {
this.vector.x += myp5.cos(this.angle) * this.stepSize;
this.vector.y += myp5.sin(this.angle) * this.stepSize;
this.isOutside = this.vector.x < 0 || this.vector.x > myp5.width || this.vector.y < 0 || this.vector.y > myp5.height;
if (this.isOutside) {
this.vector.set(myp5.random(myp5.width), myp5.random(myp5.height));
this.vectorOld = this.vector.copy();
}
myp5.strokeWeight(strokeWidth * this.stepSize);
myp5.line(this.vectorOld.x, this.vectorOld.y, this.vector.x, this.vector.y);
this.vectorOld = this.vector.copy();
this.isOutside = false;
};
Agent.prototype.update1 = function(noiseScale, noiseStrength, strokeWidth, offset) {
this.angle = myp5.noise(this.vector.x / noiseScale, this.vector.y / noiseScale) * noiseStrength + offset;
this.update(strokeWidth);
};
Agent.prototype.update2 = function(noiseScale, noiseStrength, strokeWidth) {
this.angle = myp5.noise(this.vector.x / noiseScale, this.vector.y / noiseScale) * 24;
this.angle = (this.angle - myp5.floor(this.angle)) * noiseStrength;
this.update(strokeWidth);
};