-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
executable file
·61 lines (56 loc) · 2.66 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="lib/pudzian.js"></script>
<script src="lib/pudzianDrawer.js"></script>
</head>
<body style="width: 1024px; height: 600px; margin: auto;">
<h2 id="stats"></h1>
<canvas id="myCanvas" width=18000 height="14000"></canvas>
<script type="text/javascript">
window.onload = init;
function init() {
var bin = { width: 100, height: 100, length: 100, weight: 100 };
pudzian = new Pudzian(bin);
var fits = pudzian.fit([
{ width: 99, height: 10, length: 99, weight: 1 },
{ width: 60, height: 89, length: 89, weight: 1 },
{ width: 30, height: 10, length: 79, weight: 1 },
{ width: 25, height: 70, length: 70, weight: 1 },
{ width: 50, height: 10, length: 10, weight: 1 },
{ width: 10, height: 50, length: 10, weight: 1 },
{ width: 10, height: 10, length: 50, weight: 1 },
{ width: 90, height: 50, length: 10, weight: 1 },
{ width: 90, height: 40, length: 10, weight: 1 },
{ width: 90, height: 10, length: 10, weight: 1 },
{ width: 5, height: 5, length: 5, weight: 1 }
]);
var binVolume = pudzian.bin().width * pudzian.bin().height * pudzian.bin().length;
var itemsVolume = function () {
return pudzian.items().reduce(function (sum, item) {
return sum += item.width * item.height * item.length;
}, 0);
}();
var itemsWeight = function () {
return pudzian.items().reduce(function (sum, item) {
return sum += item.weight;
}, 0);
}();
var waste = (1 - itemsVolume/binVolume) * 100;
var statsTag = document.getElementById("stats");
statsTag.innerHTML = "Fits: " + fits + "<br>Bin volume: " + binVolume + ", items volume: " + itemsVolume +
"<br>Bin max weight: " + pudzian.bin().weight + ", items weight: " + itemsWeight +
"<br>waste: " + waste.toFixed() + "%";
var pudzianDrawer = new PudzianDrawer({
root: {x: 100, y: 100, z: 100, w: pudzian.bin().width, h: pudzian.bin().height, l: pudzian.bin().length},
canvasID: "myCanvas"
});
color = [ "red", "blue", "green", "yellow", "bronze", "black", "blue", "red" ];
for (var i=0; i < pudzian.items().length; i++) {
var item = pudzian.items()[i];
pudzianDrawer.drawBox(item.x, item.y, item.z, item.width, item.height, item.length, color[i]);
};
};
</script>
</body>
</html>