Repository navigation
Expand file tree
/
Copy pathjsmodel.html
More file actions
58 lines (55 loc) · 1.7 KB
/
Copy pathjsmodel.html
File metadata and controls
58 lines (55 loc) · 1.7 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
<html>
<head>
<title>JavaScript Random Walker</title>
<script src="../lib/agentscript.js"></script>
<script>
myModel = function () {
var u = ABM.Util; // useful alias for utilities
ABM.Model.prototype.startup = function () {
console.log("startup");
};
ABM.Model.prototype.setup = function () {
console.log("setup");
this.refreshPatches = this.refreshLinks = false;
this.turtles.setUseSprites();
this.population = 100;
this.speed = .5;
this.wiggle = u.degToRad(30);
for (var i=0; i < this.patches.length; i++) {
this.patches[i].color = u.randomGray();
}
this.turtles.create(this.population);
for (var i=0; i < this.turtles.length; i++) {
var pt = this.patches.randomPt();
this.turtles[i].setXY(pt[0],pt[1]);
}
console.log("patches: " + this.patches.length + " turtles: " + this.turtles.length);
};
ABM.Model.prototype.step = function () {
for (var i=0; i < this.turtles.length; i++) {
var a = this.turtles[i];
a.rotate(u.randomCentered(this.wiggle));
a.forward(this.speed);
}
// if (this.anim.ticks % 100 === 0) {
// console.log(this.anim.toString());
// }
};
var model = new ABM.Model({
div: "layers",
size: 13,
minX: -16,
maxX: 16,
minY: -16,
maxY: 16,
isTorus: true
})
.debug() // Debug: Put Model vars in global name space
.start(); // Run model immediately after startup initialization
}
</script>
</head>
<body onload="myModel();">
<div id="layers"></div>
</body>
</html>