-
Notifications
You must be signed in to change notification settings - Fork 4
/
fittest.html
30 lines (27 loc) · 861 Bytes
/
fittest.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
<html>
<canvas id="cvs" height=100 width=100></canvas>
</html>
<script src="imageFit.js"></script>
<script>
let images = [
{width:100, height:100},
{width:150, height:80},
{width:40, height:125},
{width:100, height:300},
{width:120, height:100},
];
for (let i of images) {
i.width = Math.ceil(Math.random() * 170 + 60);
i.height = Math.ceil(Math.random() * 150 + 50);
}
let cList = fitImages(images);
let c = document.getElementById("cvs");
c.height = cList.container.height;
c.width = cList.container.width;
let ctx = c.getContext("2d");
for (let i=0; i<images.length; i++) {
let pos = cList.pos[i];
let size = images[i];
ctx.strokeRect(pos.x, pos.y, size.width, size.height);
}
</script>