-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeconstruction.html
85 lines (68 loc) · 2.15 KB
/
deconstruction.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Smash the Walls Deconstruction</title>
<style>
html,
body,
svg {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<svg id="svg" width="100%" height="100%"></svg>
<script>
window.onload = () => {
let rowCount = 4;
let colCount = 8;
let width = document.body.offsetWidth;
let height = document.body.offsetHeight;
let stray = 50;
const svgns = "http://www.w3.org/2000/svg";
const svg = document.getElementById("svg");
svg.setAttribute("width", width);
svg.setAttribute("height", height);
let points = getPoints(width, height, rowCount, colCount, stray);
console.log(points);
for (let row of points) {
for (let col of row) {
let dot = document.createElementNS(svgns, "circle", svg);
dot.setAttributeNS(null, "cx", col.x);
dot.setAttributeNS(null, "cy", col.y);
dot.setAttributeNS(null, "r", 10);
dot.setAttributeNS(null, "fill", "red");
svg.appendChild(dot);
}
}
};
let getPoints = (width, height, rows, cols, stray) => {
let points = [];
let widthInt = width / cols;
let heightInt = height / rows;
console.log("cols: " + cols);
console.log("rows: " + rows);
for (let i = 0; i <= cols; i++) {
let next = [];
for (let j = 0; j <= rows; j++) {
let x = i * widthInt + (Math.random() * stray * 2 - stray);
let y = j * heightInt + (Math.random() * stray * 2 - stray);
if (i == 0) x = 0;
else if (i == cols) x = width;
if (j == 0) y = 0;
else if (j == rows) y = height;
next.push({x: x, y: y});
}
points.push(next);
}
return points;
};
</script>
</body>
</html>