Repository navigation
Expand file tree
/
Copy pathprefattach.html
More file actions
57 lines (50 loc) · 1.76 KB
/
Copy pathprefattach.html
File metadata and controls
57 lines (50 loc) · 1.76 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
<html>
<head>
<title>Pref-Attach Model</title>
<script src="../lib/agentscript.js"></script>
<script src="../tools/coffee-script.js"></script>
<script type="text/coffeescript">
u = ABM.Util # ABM.Util alias
class MyModel extends ABM.Model
setup: ->
@refreshPatches = false # for static patches
# globals
@circleLayout = true
@hist = []
@stopTick = 400
# defaults
@turtles.setDefault "shape", "circle"
@links.setDefault "thickness", .75 # Easier to see thiner link
@turtles.create 1; @makeNode @turtles[0]
step: ->
@makeNode @findPartner()
a.size = Math.sqrt a.linkNeighbors().length for a in @turtles
@links.layoutCircle @turtles, @patches.maxX * 0.9
@hist = u.histOf @turtles, 1, (a) -> a.linkNeighbors().length
console.log "Tick: #{@anim.ticks} Histogram: [#{@hist}]" if @anim.ticks % 25 is 0
(console.log "Stopping at stopTick: #{@anim.ticks}"; @stop()) if @anim.ticks is @stopTick
makeNode: (toNode) ->
@turtles.create 1, (a) =>
@links.create a, toNode
a.moveTo toNode; a.forward 8
findPartner: ->
u.oneOf @links.oneOf().bothEnds() # or @links.allEnds().oneOf()
# div, patchSize, minX, maxX, minY, maxY, isTorus, hasNeighbors
# Defaults: 13, -16, 16, -16, 16, false, true
model = new MyModel {
div: "layers",
size: 5,
minX: -45,
maxX: 45,
minY: -45,
maxY: 45,
hasNeighbors: false
}
model.debug() # Debug: Put Model vars in global name space
model.start() # Run model immediately after startup initialization
</script>
</head>
<body>
<div id="layers"></div>
</body>
</html>