-
Notifications
You must be signed in to change notification settings - Fork 0
/
digit.js
48 lines (43 loc) · 1.15 KB
/
digit.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
46
47
48
function Digit(offsetx, offsety) {
this.digit = -1;
this.offsetX = offsetx;
this.offsetY = offsety;
this.vehicles = [];
}
Digit.prototype.init = function (numPoints) {
for (var i = 0; i < numPoints; i++) {
var x = floor(random(width));
var y = floor(random(height));
var vehicle = new Vehicle(x, y);
this.vehicles.push(vehicle);
}
}
Digit.prototype.update = function () {
for (var i = 0; i < this.vehicles.length; i++) {
var v = this.vehicles[i];
v.behaviors();
v.update();
}
}
Digit.prototype.show = function() {
stroke(255);
for (var i = 0; i < this.vehicles.length; i++) {
var v = this.vehicles[i];
v.show();
}
}
Digit.prototype.setTargets = function(targets) {
if (this.digit != targets.d)
{
this.digit = targets.d;
for (var i = 0; i < this.vehicles.length; i++) {
var v = this.vehicles[i];
v.target.x = targets.points[i].x + this.offsetX;
v.target.y = targets.points[i].y + this.offsetY;
v.color = targets.points[i].color;
}
}
else {
// TODO shuffle ?
}
}