-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAgentSystem.js
More file actions
68 lines (56 loc) · 1.4 KB
/
AgentSystem.js
File metadata and controls
68 lines (56 loc) · 1.4 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/// An AgentSystem is a set of Agents.
/// It's different from a particle system in that it's ready to implement some individual intelligence that stacks up with the group dynamics.
function AgentSystem(Nagents = 500) {
this.agents = new Array(Nagents);
this.flowField = new FlowField(20,20,1);
// -------------------------------------------------
// -------------------------------------------------
this.init = function()
{
for(i=0; i<Nagents; i++)
{
this.agents[i] = new Agent(createVector(random(0,W), random(0,H)), 1 + random(0,2), 1, this, this.flowField);
}
}
this.init();
// -------------------------------------------------
this.update = function()
{
for(i=0; i<Nagents; i++)
{
this.agents[i].update();
}
}
// -------------------------------------------------
this.getAgents = function()
{
return this.agents;
}
this.draw = function()
{
this.drawFlowField();
for(i=0; i<Nagents; i++)
{
this.agents[i].draw();
}
}
// -------------------------------------------------
this.addImpulse = function(position, power)
{
for(i=0; i<Nagents; i++)
{
this.agents[i].addImpulse(position, power);
}
}
// -------------------------------------------------
this.drawFlowField = function()
{
if(this.flowField === undefined)
{
}
else
{
this.flowField.draw();
}
}
}