forked from darkskyapp/delaunay-fast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
45 lines (37 loc) · 1.17 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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="1024" height="1024">
</canvas>
<script type="text/javascript" src="delaunay.js">
</script>
<script type="text/javascript">
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
vertices = new Array(2048),
i, x, y;
for(i = vertices.length; i--; ) {
do {
x = Math.random() - 0.5;
y = Math.random() - 0.5;
} while(x * x + y * y > 0.25);
x = (x * 0.96875 + 0.5) * canvas.width;
y = (y * 0.96875 + 0.5) * canvas.height;
vertices[i] = [x, y];
}
console.time("triangulate");
var triangles = Delaunay.triangulate(vertices);
console.timeEnd("triangulate");
for(i = triangles.length; i; ) {
ctx.beginPath();
--i; ctx.moveTo(vertices[triangles[i]][0], vertices[triangles[i]][1]);
--i; ctx.lineTo(vertices[triangles[i]][0], vertices[triangles[i]][1]);
--i; ctx.lineTo(vertices[triangles[i]][0], vertices[triangles[i]][1]);
ctx.closePath();
ctx.stroke();
}
</script>
</body>
</html>