// Generated by CoffeeScript 1.10.0 (function() { var cells, cells_data, defs, enter_gradients, gradients, height, radius, sites, sites_data, svg, voronoi, width; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; defs = svg.append('defs'); radius = 10; sites_data = d3.range(20).map(function() { return { x: Math.round(Math.random() * (width - radius * 2) + radius), y: Math.round(Math.random() * (height - radius * 2) + radius) }; }); voronoi = d3.voronoi().x(function(d) { return d.x; }).y(function(d) { return d.y; }).extent([[-1, -1], [width + 1, height + 1]]); cells_data = voronoi.polygons(sites_data); gradients = defs.selectAll('.gradient').data(sites_data); enter_gradients = gradients.enter().append('radialGradient').attrs({ "class": 'gradient', gradientUnits: 'userSpaceOnUse', id: function(d, i) { return "gradient_" + i; }, cx: function(d) { return d.x; }, cy: function(d) { return d.y; }, r: 300 }); enter_gradients.append('stop').attrs({ offset: '0%', 'stop-color': 'white' }); enter_gradients.append('stop').attrs({ offset: '100%', 'stop-color': 'black' }); cells = svg.selectAll('.cell').data(cells_data); cells.enter().append('path').attrs({ "class": 'cell', d: function(d) { if (d == null) { return null; } else { return "M" + d.join("L") + "Z"; } }, fill: function(d, i) { return "url(#gradient_" + i + ")"; } }); sites = svg.selectAll('.site').data(sites_data); sites.enter().append('circle').attrs({ "class": 'site', r: radius, cx: function(d) { return d.x; }, cy: function(d) { return d.y; } }); }).call(this);