-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
340 lines (324 loc) · 17.2 KB
/
index.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html lang="en">
<head>
<!--Google -->
<meta name="google-site-verification" content="GAE-uIRdnigcZt8VF2XsG0-2fF-ZrgOAx_rN-j-W1no" />
<!-- BOOTSTRAP -->
<link rel="stylesheet" href="vendor/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="style/style.css">
<script src="vendor/js/jquery-3.3.1.slim.min.js"></script>
<script src="vendor/js/popper.min.js"></script>
<script src="vendor/js/bootstrap.min.js"></script>
<!-- p5 -->
<script src="vendor/js/p5.min.js"></script>
<!-- A* -->
<script src="source/main.js"></script>
<script src="source/astar.js"></script>
<script src="source/fileManager.js"></script>
<title>A* pathfinding</title>
</head>
<body>
<!-- Header -->
<header>
<nav class="navbar navbar-expand-md navbar-dark bg-dark " style="position: fixed; width: 100%; z-index: 1;">
<a class="navbar-brand" style="justify-content: center;">
<h2>A* pathfinding algorithm</h2>
</a>
<div id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<div>
<button id="b_play" type="button" class="btn btn-outline-light" onclick="startAlgotithm()">
<i class="fa fa-play"></i>
Start algorithm
</button>
<button id="b_pause" type="button" class="btn btn-outline-light" onclick="setStatus('pause')">
<i class="fa fa-pause"></i>
Pause
</button>
<button id="b_stop" type="button" class="btn btn-outline-light" onclick="setStatus('stop')">
<i class="fa fa-stop"></i>
Stop
</button>
<br>
<button id="b_clear" type="button" class="btn btn-outline-light" onclick="clearBoard()">
<i class="fa fa-trash"></i>
Clear
</button>
<button id="b_settings" type="button" class="btn btn-outline-light" onclick="callSettings()">
<i class="fa fa-cog"></i>
Settings
</button>
<button id="b_saveLoad" type="button" class="btn btn-outline-light" onclick="callSaveLoad()">
<i class="fa fa-archive"></i>
Save/Load
</button>
<button type="button" class="btn btn-outline-light" style="margin-left: 10px;" onclick="window.open('https://github.com/TendTo/AstarPathfindingAlgorithm')">
<i class="fa fa-github"></i>
</button>
</div>
</li>
<li id="result" style="margin-left: 20px; font-size: small;"></li>
<!--
<li style="position: fixed; align-self: center; right: 10px;">
<a href="http://validator.w3.org/check/referer" target="_blank"><img src="graphic/htmlValidator.png" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>
</li>
-->
<li style="position: fixed; align-self: center; right: 30px;">
<a href="translations/index-it.html"><img src="graphic/language.svg" alt="Lingua italiana" height="40" width="40"> </a>
<a href="translations/index-it.html"> italiano</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container-fluid" style="margin-top: 10px;">
<hr>
<div class="row">
<!-- Palette -->
<div class="tools ml-3" style="overflow-y:visible; position: fixed; top: 110px; left: 30px; z-index: 1;">
<div class="list-group float-right justify-content" style="min-width: 50px; max-width: 60px">
<button type="button" onclick="setPalette('ground')" class="list-group-item list-group-item-action pl-1 palette-button">
Ground
<img src="graphic/ground.svg" style="width: 50px;" alt="Ground icon" />
</button>
<button type="button" onclick="setPalette('wall')" class="list-group-item list-group-item-action pl-1 palette-button">
Wall
<img src="graphic/wall.svg" style="width: 50px;" alt="Wall icon" />
</button>
<button type="button" onclick="setPalette('special_ground')" class="list-group-item list-group-item-action pl-1 palette-button">
Special
ground
<img src="graphic/special_ground.svg" style="width: 50px;" alt="Special ground icon" />
</button>
<button type="button" onclick="setPalette('start')" class="list-group-item list-group-item-action pl-1 palette-button">
Start
<img src="graphic/start.svg" style="width: 50px;" alt="Start icon" />
</button>
<button type="button" onclick="setPalette('end')" class="list-group-item list-group-item-action pl-1 palette-button">
End
<img src="graphic/end.svg" style="width: 50px;" alt="End icon" />
</button>
</div>
</div>
<div class="col-10 pl-0">
<!-- Canvas -->
<div id="canvas" style="margin-left: 130px; margin-top: 110px; z-index: -1;">
</div>
</div>
</div>
</div>
<!-- Settings modal-->
<div id="settings" class="modal fade modal-class" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered " role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Settings</h3>
</div>
<div class="modal-body row">
<table>
<tbody>
<tr>
<th> Rows <i data-toggle="tooltip" data-placement="top" title="Number of rows<br>Min 1 - Max 99"> ?</i></th>
<th> </th>
<th> Columns <i data-toggle="tooltip" data-placement="top" title="Number of columns<br>Min 1 - Max 99"> ?</i></th>
</tr>
<tr>
<th><input id="h" value="10" type="number" style="width: 4em" step="1" oninput="checkInput(this)" onblur="validateInput(this, 1, 99)"></th>
<th> x </th>
<th><input id="w" value="10" type="number" style="width: 4em" step="1" oninput="checkInput(this)" onblur="validateInput(this, 1, 99)"></th>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<!--Spacing for the table-->
<th><br></th>
<th><br></th>
<th><br></th>
</tr>
<tr>
<th> Cell size <i data-toggle="tooltip" data-placement="top" title="Size of each cell<br>Min 6 - Max 99"> ?</i></th>
<th> </th>
<th> Framerate <i data-toggle="tooltip" data-placement="top" title="Framerate of the animation<br>Min 0.1 - Max 60"> ?</i></th>
</tr>
<tr>
<th><input id="s" value="70" type="number" style="width: 4em" step="1" oninput="checkInput(this)" onblur="validateInput(this, 6, 99)"></th>
<th> </th>
<th><input id="f" value="2" type="number" style="width: 4em" step="0.5" onblur="validateInput(this, 0.1, 60)"></th>
</tr>
<tr>
<!--Spacing for the table-->
<th><br></th>
<th><br></th>
<th><br></th>
</tr>
<tr>
<th> <b>+</b> direction cost <i data-toggle="tooltip" data-placement="top" title="Cost of moving vertically or horizontally<br>Min 0 - Max 50"> ?</i>
</th>
<th> </th>
<th> <b>x</b> direction cost <i data-toggle="tooltip" data-placement="top" title="Cost of moving diagonally<br>Min 0 - Max 50"> ?</i>
</th>
</tr>
<tr>
<th><input id="d1" value="10" type="number" style="width: 4em" step="1" oninput="checkInput(this)" onblur="validateInput(this, 0, 50)"></th>
<th></th>
<th><input id="d2" value="14" type="number" style="width: 4em" step="1" oninput="checkInput(this)" onblur="validateInput(this, 0, 50)"></th>
</tr>
<tr>
<!--Spacing for the table-->
<th><br></th>
<th><br></th>
<th><br></th>
</tr>
<tr>
<th> H coefficient <i data-toggle="tooltip" data-placement="top" title="Coefficient used when calculating the h value<br>Min 0 - Max 99"> ?</i>
</th>
<th> </th>
<th> Special ground <i data-toggle="tooltip" data-placement="top" title="Traversing the special ground will cost X times the normal ground cost<br>Only used for the g value<br>Min 0 - Max 99"> ?</i>
</th>
</tr>
<tr>
<th><input id="hm" value="2" type="number" style="width: 4em" step="0.5" onblur="validateInput(this, 0, 99)"></th>
<th></th>
<th><input id="sm" value="2" type="number" style="width: 4em" step="0.5" onblur="validateInput(this, 0, 99)"></th>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<!--Spacing for the table-->
<th><br></th>
</tr>
<tr>
<th> Heuristic <i data-toggle="tooltip" data-placement="top" title="Heuristic used to calculate the h value for each node"> ?</i></th>
</tr>
<tr>
<th> <select id="hsearch">
<option value="1">Manatthan distance</option>
<option value="2">Diagonal distance</option>
<option value="3">Euclidian distance</option>
<option value="4">Dijkstra (h = 0)</option>
</select></th>
</tr>
<tr>
<!--Spacing for the table-->
<th><br></th>
</tr>
<tr>
<th>
<input type="checkbox" class="form-check-input, ml-0" id="d">
<label class="form-check-label" for="d">Can move diagonally <i data-toggle="tooltip"
data-placement="top"
title="Whether or not diagonal movements should be considered"> ?</i></label>
</th>
</tr>
</tbody>
</table>
</div>
<br><br>
<div class=" modal-footer">
<button class="btn-secondary" type="button" data-dismiss="modal" onclick="cancel()">Cancel</button>
<button class="btn-primary" type="button" data-dismiss="modal" onclick="apply()">Apply</button>
</div>
</div>
</div>
</div>
<!-- Save/Load modal-->
<div id="saveLoad" class="modal fade modal-class" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered " role="document" style="height: fill-content; width: 215px;">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Save/Load</h3>
</div>
<div class="modal-body row">
<a download="AstarSave.astar" href="#" id="saveProjectFile" onclick="FileManager.saveFile()">
<button type="button" class="btn btn-outline-light">
<i class="fa fa-save"></i>
Save
</button>
</a>
<label class="btn btn-outline-light" style="margin-left:10px">
<input id="projectFile" type="file" onchange="FileManager.loadFile(event)" hidden></input>
<i class="fa fa-upload"></i>
Load
</label>
</div>
<br><br>
<div class=" modal-footer">
<button class="btn-primary" type="button" data-dismiss="modal" onclick="cancel()">Dismiss</button>
</div>
</div>
</div>
</div>
<!-- Snackbar-->
<div id="snackbar">Invalid start or end</div>
<script>
document.validateInput = validateInput;
document.checkInput = checkInput;
/**
* Used to enable the tooltips
*/
$(function() {
$('[data-toggle="tooltip"]').tooltip({
html: true
})
})
/**
* Prevents the use of unwanted characters
* @param {any} ob - html input field
*/
function checkInput(ob) {
ob.value = ob.value.replace(/[^0-9]/g, '');
}
/**
* Checks that the value is between the constrains
* @param {any} ob - html input field
* @param {number} min - minimum value allowed
* @param {number} max - maximum value allowed
*/
function validateInput(ob, min, max) {
if (ob.value == "")
ob.value = min;
else if (ob.value > max)
ob.value = max;
else if (ob.value < min)
ob.value = min;
}
/**
* Change the status value and shows the settings modal
*/
function callSettings() {
setStatus('settings');
$('#settings').modal('show');
}
/**
* Change the status value and shows the save/load modal
*/
function callSaveLoad() {
setStatus('settings');
$('#saveLoad').modal('show');
}
/**
* Show the results of the algorithm
* @param {number} distance - distance result from the start point to hte end point
* @param {number} stepCounter - times of calls to the function 'stepSolution'
* @param {number} fcounter - times an fvalue got evalueted
* @param {number} time - time enlapsed
*/
function setResults(distance, stepCounter, fcounter, time) {
if (distance < 0)
document.getElementById("result").innerHTML = "";
else
document.getElementById("result").innerHTML =
"Shortest distance found: " + distance + "<br>" +
"Number of steps: " + stepCounter + "<br>" +
"Number of f value calculated: " + fcounter + "<br>" +
"Time elapsed " + (time / 1000).toFixed(3) + " sec";
}
</script>
</body>
</html>