[ Launch: voronoi ] 6232b10f4b80de7056d06b0e06753204 by jhprinz
[ Launch: test ] 4653053 by enjalot
[ Launch: test ] 4652017 by enjalot
[ Launch: test ] 4582399 by enjalot
-
-
Save jhprinz/6232b10f4b80de7056d06b0e06753204 to your computer and use it in GitHub Desktop.
voronoi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"description":"voronoi","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.7,"thumbnail":"http://i.imgur.com/Z4ghHZY.png","fullscreen":false,"ajax-caching":true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var svg = d3.select("svg").on("touchmove mousemove", moved), | |
| width = +svg.attr("width"), | |
| height = +svg.attr("height"); | |
| var sites = d3.range(100) | |
| .map(function(d) { return [Math.random() * width, Math.random() * height]; }); | |
| var voronoi = d3.voronoi() | |
| .extent([[-1, -1], [width + 1, height + 1]]); | |
| var polygon = svg.append("g") | |
| .attr("class", "polygons") | |
| .selectAll("path") | |
| .data(voronoi.polygons(sites)) | |
| .enter().append("path") | |
| .call(redrawPolygon); | |
| var link = svg.append("g") | |
| .attr("class", "links") | |
| .selectAll("line") | |
| .data(voronoi.links(sites)) | |
| .enter().append("line") | |
| .call(redrawLink); | |
| var site = svg.append("g") | |
| .attr("class", "sites") | |
| .selectAll("circle") | |
| .data(sites) | |
| .enter().append("circle") | |
| .attr("r", 2.5) | |
| .call(redrawSite); | |
| function moved() { | |
| sites[0] = d3.mouse(this); | |
| redraw(); | |
| } | |
| function redraw() { | |
| var diagram = voronoi(sites); | |
| polygon = polygon.data(diagram.polygons()).call(redrawPolygon); | |
| link = link.data(diagram.links()), link.exit().remove(); | |
| link = link.enter().append("line").merge(link).call(redrawLink); | |
| site = site.data(sites).call(redrawSite); | |
| } | |
| function redrawPolygon(polygon) { | |
| polygon | |
| .attr("d", function(d) { return d ? "M" + d.join("L") + "Z" : null; }); | |
| } | |
| function redrawLink(link) { | |
| link | |
| .attr("x1", function(d) { return d.source[0]; }) | |
| .attr("y1", function(d) { return d.source[1]; }) | |
| .attr("x2", function(d) { return d.target[0]; }) | |
| .attr("y2", function(d) { return d.target[1]; }); | |
| } | |
| function redrawSite(site) { | |
| site | |
| .attr("cx", function(d) { return d[0]; }) | |
| .attr("cy", function(d) { return d[1]; }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .links { | |
| stroke: #000; | |
| stroke-opacity: 0.2; | |
| } | |
| .polygons { | |
| fill: none; | |
| stroke: #000; | |
| } | |
| .polygons :first-child { | |
| fill: #f00; | |
| } | |
| .sites { | |
| fill: #000; | |
| stroke: #fff; | |
| } | |
| .sites :first-child { | |
| fill: #fff; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment