-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
148 lines (107 loc) · 2.7 KB
/
main.html
File metadata and controls
148 lines (107 loc) · 2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<html>
<head>
<script type="text/javascript" src="external/ocanvas-2.8.1.js"></script>
<script type="text/javascript" src="external/underscore.js"></script>
<script type="text/javascript" src="world.js"></script>
<script type="text/javascript" src="agent.js"></script>
<script type="text/javascript" src="simulation.js"></script>
<script type="text/javascript">
// Fix recreating of the canvas
// create Juks walking one towrds each other
// create choosing behavior between traits like in article
oCanvas.domReady( function() {
var A = new Agent(-50,-50);
var B = new Agent(-50,50);
var C = new Agent(50,50);
var D = new Agent(50,-50);
A.target = B;
B.target = C;
C.target = D;
D.target = A;
var world = new World(
{
m_CanvasID: "#myCanvas",
AGENT_SIZE: 3,
step : function (world) {
_.each(world.agents,function(agent) {
if (agent!=null) {
var dx = agent.target.x - agent.x,
dy = agent.target.y - agent.y,
a = Math.atan2(dy, dx);
var dx1 = Math.cos(a), dy1 = Math.sin(a);
world.moveAgent(Math.round(dx1),Math.round(dy1),agent);
}
}
);
}
}
);
var conf1 = [A,B,C,D];
world.addAgentsToWorld(conf1);
world.startStepping();
}
);
var inputs = {
0: '\
var world = new World( \n\
{ \n\
m_CanvasID: "#myCanvas", \n\
AGENT_SIZE: 1, \n\
step : Simulation.moveRandomly \n\
} \n\
); \n\
\n\
world.addAgentsToWorld(Simulation.randStartConf(100,10)); \n\
world.startStepping(); \n\
',
1: '\
var world = new World( \n\
{ \n\
m_CanvasID: "#myCanvas", \n\
AGENT_SIZE: 10, \n\
step : Simulation.GameOfLife_Step \n\
} \n\
); \n\
\n\
var conf1 = [\n\
new Agent(0,0),\n\
new Agent(1,0),\n\
new Agent(2,0),\n\
new Agent(2,1),\n\
new Agent(1,2),\n\
];\n\
\n\
world.addAgentsToWorld(conf1);\n\
world.startStepping(); \n\
'
}
function paste(i) {
var input = document.getElementById('input');
input.value = inputs[i];
}
function processInput() {
var suggestionsDiv = document.getElementById('Suggestions');
suggestionsDiv.parentElement.removeChild(suggestionsDiv);
var inputTxt = document.getElementById('input').value;
eval(inputTxt);
}
</script>
</head>
<body>
World Input
<br/>
<textarea id = "input" cols="100" rows="20"> </textarea>
<br/>
<div id="Suggestions">
<a href="javascript:paste(0)" >Random configuration - Moves random</a>
......
<a href="javascript:paste(1)" >Game Of Life - Glider</a>
</div>
<br/>
<input type="button" value="Process Input" onclick="processInput()"></input>
<br/>
<br/><br/>
<canvas id="myCanvas" width="500" height="500" >
</canvas>
</body>
</html>