-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
28 lines (23 loc) · 879 Bytes
/
script.js
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
var w = parseInt($(window).width());
var h = parseInt($(window).height());
var paddingPercentage = 5
var wPadding = parseInt((w*paddingPercentage)/100);
var hPadding = parseInt((w*paddingPercentage)/100);
var range = 500
function randomIntFromInterval(min,max) {
return parseInt(Math.floor(Math.random()*(max-min+1)+min));
}
var vertices = d3.range(range).map(function(d) {
return [
randomIntFromInterval(-wPadding, w + wPadding),
randomIntFromInterval(-hPadding, h + wPadding)
];
});
var delaunay = d3.voronoi().triangles(vertices)
var svg = d3.select("body").append("svg").attr("preserveAspectRatio", "xMidYMid slice").attr("viewBox", [0, 0, w, h].join(' '))
svg.append("g").selectAll("path").data(delaunay).enter().append("path")
.attr("class", function(d, i) {
return "q" + (i % 9) + "-9";
}).attr("d", function(d) {
return "M" + d.join("L") + "Z";
});