forked from qrohlf/trianglify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-points-example.html
50 lines (45 loc) · 1.26 KB
/
custom-points-example.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
<!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">
<title>Trianglify custom points example</title>
<style>
html, body {
margin: 0 0;
padding: 0 0;
text-align: center;
font-size: 0;
}
</style>
</head>
<body>
<script src="../dist/trianglify.bundle.debug.js"></script>
<script>
const width = 700
const height = 700
// generate a spiral using polar coordinates
const points = []
const NUM_POINTS = 150
let r = 0
const rStep = width / 2 / NUM_POINTS
let theta = 0
const thetaStep = Math.PI / NUM_POINTS * 18
for (let i = 0; i < NUM_POINTS; i++) {
const x = width / 2 + r * Math.cos(theta)
const y = height / 2 + r * Math.sin(theta)
const point = [x, y]
points.push(point)
r += rStep
theta = (theta + thetaStep) % (2 * Math.PI)
}
// apply trianglify to convert the points to polygons and apply the color
// gradient
var pattern = trianglify({height, width, points})
// use the toCanvas function to render the generated geometry to an HTML5
// canvas element
document.body.appendChild(pattern.toCanvas())
</script>
</body>
</html>