-
Notifications
You must be signed in to change notification settings - Fork 1
/
library-pathfind.html
64 lines (54 loc) · 1.94 KB
/
library-pathfind.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
<!doctype html>
<html>
<head>
<title>Library Pathfinding</title>
<style>
.blok {
display: block;
position: absolute;
font-size: 4px;
width: 4em;
height: 4em;
line-height: 4em;
border-radius: 50%;
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<div id="asal"></div>
<div id="tujuan"></div>
<div id="jalur"></div>
<script type="text/javascript" src="./lib/pathfinding-browser.js"></script>
<script type="text/javascript" src="./js/navigasi.js"></script>
<script type="text/javascript" src="./js/gedungPerpustakaanUnila.js"></script>
<script async>
var asal = document.querySelector("#asal");
var tujuan = document.querySelector("#tujuan");
var jalur = document.querySelector("#jalur");
var nodes = gedungPerpustakaan();
// Titik awal | Coba diganti dengan node yang ada di jalur atau pun yang tidak dibuat di jalur
var startNode = nodes['PMP'];
console.log(startNode);
asal.innerHTML = "Asal = (" + startNode.x + ", " + startNode.y + ", " + startNode.z + ")";
// Tujuan | Coba diganti dengan node yang ada di jalur atau pun yang tidak dibuat di jalur
var endNode = nodes['RKP'];
console.log(endNode);
tujuan.innerHTML = "Tujuan = (" + endNode.x + ", " + endNode.y + ", " + endNode.z + ")";
var path;
// Cari jalan
path = new PF.AStarFinder().findPath(startNode, endNode, nodes);
console.log(path);
for(let i = 0; i < path.length; i++) {
jalur.innerHTML += `
<div class="blok"
style="background-color: rgba(${path[i][2]*100},0,${60+(i*10)}, 0.3);
left: ${path[i][0]*4}em;
top: ${path[i][1]*4}em">
${getKode(nodes, path[i])}
</div>`;
}
</script>
</body>
</html>