Repository navigation
Expand file tree
/
Copy pathrandomSquare.html
More file actions
65 lines (58 loc) · 1.79 KB
/
Copy pathrandomSquare.html
File metadata and controls
65 lines (58 loc) · 1.79 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<svg width="1200" height="800">
<!-- <rect x="0" y="0" width="100%" height="100%" fill="lightgray" /> -->
<!-- <g id="content">
</g> -->
</svg>
<script>
let content = document.getElementById('content');
class Box {
constructor() {
this._color = '#' + Math.floor(Math.random() * 16777215).toString(16);
this._x = Math.floor(Math.random() * 600);
this._y = Math.floor(Math.random() * 400);
this._width = 100 + Math.floor(Math.random() * 500);
this._height = 100 + Math.floor(Math.random() * 300);
}
}
// class boxSet {
// constructor() {
// this._boxSet = [];
// }
// }
class BoxView {
constructor(box) {
this._svg = document.getElementsByTagName('svg')[0];
this._box = box;
}
show() {
boxView._svg.innerHTML = `
<rect width="${boxView._box._width}" height="${boxView._box._height}" x="${boxView._box._x}" y="${boxView._box._y}" style="fill:${boxView._box._color};stroke-width:3;stroke:rgb(0,0,0)" />
`;
}
}
var box = new Box();
let boxSet = [
new Box(),
new Box(),
new Box(),
new Box(),
];
var boxView = new BoxView(box);
boxView.show();
</script>
</body>
</html>