-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsea.html
78 lines (71 loc) · 2.57 KB
/
sea.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
<link rel="stylesheet" href="css/style.css">
<body style="height: 100vh;">
<canvas id="sea-block" width="600" height="400">
Извините, ваш браузер нет поддерживает<canvas> элемент.
</canvas>
<div class="icebergs"></div>
<canvas id="land" width="300" height="300">
Извините, ваш браузер нет поддерживает<canvas> элемент.
</canvas>
</body>
<script src="sea.js"></script>
<script src="multigeometry.js"></script>
<script>
var land = document.getElementById("land")
var width = land.clientWidth
var height = land.clientHeight
var ctx = land.getContext("2d")
var points = [];
for (var ind = 0; ind < 50; ind++) {
w = Math.random() * width
h = Math.random() * height
points.push([w,h]);
// ctx.arc(w,h,2,0,2*Math.PI)
}
ctx.beginPath()
var hull = convexHull(points);
ctx.moveTo(points[0][0],points[0][1])
for (let index = 1; index < hull.length; index++) {
let pos = hull[index];
ctx.lineTo(pos[0],pos[1])
console.log(pos)
}
ctx.lineTo(points[0][0],points[0][1])
ctx.stroke()
</script>
<script>
// var icebergs = document.querySelector(".icebergs")
// var max = getRndInteger(1,5)
// for (let i = 0; i < max; i++) {
// var iceberg = document.createElement("canvas")
// var width = getRndInteger(40,100)
// var height = getRndInteger(40,100)
// iceberg.width = width
// iceberg.height = height
// iceberg.className = "iceberg"
// let y = getRndInteger(height/2,icebergs.clientHeight-height/2)
// let x = getRndInteger(width/2,icebergs.clientWidth-width/2)
// iceberg.style.top = y
// iceberg.style.left = x
// var ctx = iceberg.getContext("2d")
// var points = [];
// for (var ind = 0; ind < 10; ind++) {
// points.push([Math.random() * width, Math.random() * height]);
// }
// var hull = convexHull(points);
// ctx.beginPath()
// ctx.moveTo(points[0][0],points[0][1])
// for (let index = 1; index < hull.length; index++) {
// let pos = hull[index];
// ctx.lineTo(pos[0],pos[1])
// console.log(pos)
// }
// ctx.lineTo(points[0][0],points[0][1])
// ctx.fillStyle = "#deebff"
// ctx.strokeStyle = "#c8ddff"
// ctx.lineWidth = 2
// ctx.stroke()
// ctx.fill()
// icebergs.appendChild(iceberg)
// }
</script>