-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (87 loc) · 3.09 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>voronoi-breakable</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.5.9/css/pico.min.css">
<style>
:root {
--max-width: 1280px;
}
a:hover {
text-decoration: underline;
}
header {
max-width: var(--max-width);
margin: 50px auto auto auto;
}
header, main {
padding: 0 !important;
}
canvas {
margin: 0 0 0 15%;
padding: 0;
cursor: default;
display: block;
}
canvas {
cursor: default;
margin: 0 0 auto auto;
display: block;
}
#canvas-container {
text-align: center;
max-width: var(--max-width);
/* This will make the canvas responsive without the need to resize */
width: 100%;
object-fit: contain;
}
details p {
margin-bottom: 10px;
}
.t1008-grid {
max-width: var(--max-width);
display: grid;
grid-template-columns: 2fr 0.5fr;
/*grid-template-rows: 1.6fr 0.4fr;*/
gap: 0 0;
grid-auto-flow: row;
grid-template-areas: '. .' '. .';
}
</style>
</head>
<body>
<header>
<h2>Breakable rigid bodies using Voronoi diagrams</h2>
<details open>
<summary>About</summary>
<p>You can click anywhere on the canvas to shoot more boxes.</p>
<p>The voronoi diagram is calculated on-the-fly in real-time, and the number of sites is randomized using a random point spray.</p>
<p>Obviously it's not the most efficient way to do that but for the purpose of this demo it is fast enough.</p>
<p>NOTE: This demo is just a simple poc tech demo, might invest more in the future to make this code better written.
but for the time being this is just a research/poc/educational project.</p>
</details>
<details>
<summary>Source Code</summary>
<p>Can be found on my <a href="https://github.com/topaz1008/voronoi-breakable/" target="_blank">Github</a>.
</p>
</details>
<details>
<summary>Credits</summary>
<p>This demo uses <a href="https://github.com/liabru/matter-js" target="_blank">matter.js</a> 2D physics engine
and <a href="https://github.com/gorhill/Javascript-Voronoi" target="_blank">Javascript-Voronoi</a> library
by gorhill for calculating the voronoi diagram..</p>
</details>
</header>
<main id="main-grid" class="t1008-grid">
<div id="canvas-container">
<!-- canvas goes here -->
</div>
</main>
<script src="node_modules/voronoi/rhill-voronoi-core.js"></script>
<script src="node_modules/matter-js/build/matter.dev.js"></script>
<script src="src/main.js" type="module"></script>
</body>
</html>