Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created May 1, 2013 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/5493432 to your computer and use it in GitHub Desktop.
Save enjalot/5493432 to your computer and use it in GitHub Desktop.
simple voronoi
{"description":"simple voronoi","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"points.json":{"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}},"fullscreen":false,"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,"thumbnail":"http://i.imgur.com/dR1mfxr.png"}
var vertices = tributary.points.map(function(d) {
return [d.x, d.y]
});
var svg = d3.select("svg");
svg.selectAll("circle")
.data(vertices)
.enter()
.append("circle")
.attr({
cx: function(d) { return d[0] },
cy: function(d) { return d[1] },
r: 5
})
var voronoi = d3.geom.voronoi(vertices)
var pathFn = function(d) {
return "M" + d.join("L") + "Z";
}
svg.selectAll("path")
.data(voronoi)
.enter()
.append("path")
.attr("d", pathFn)
.classed("voronoi", true)
[
{"x": 100, "y": 100},
{"x": 150, "y": 120},
{"x": 200, "y": 130},
{"x": 100, "y": 400},
{"x": 100, "y": 500},
{"x": 140, "y": 400},
{"x": 550, "y": 400},
{"x": 450, "y": 350},
{"x": 238, "y": 309},
{"x": 321, "y": 500},
{"x": 140, "y": 223},
{"x": 322, "y": 213},
{"x": 648, "y": 350},
{"x": 587, "y": 120}
]
.voronoi {
fill: #8AEEEE;
stroke: #000000;
fill-opacity: 0.5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment