Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Created June 9, 2012 02:06
Show Gist options
  • Select an option

  • Save thinkjson/2899088 to your computer and use it in GitHub Desktop.

Select an option

Save thinkjson/2899088 to your computer and use it in GitHub Desktop.
Visit http://www.dotjs.eu/ and run this in the JavaScript console :-)
function update(){vertices[0]=d3.mouse(this);svg.selectAll("path").data(d3.geom.voronoi(vertices).map(function(a){return"M"+a.join("L")+"Z"})).filter(function(a){return this.getAttribute("d")!=a}).attr("d",function(a){return a})}$(".page").remove();$(".header").remove();$(".footer").height(window.innerHeight).children().remove();var width=window.innerWidth,height=window.innerHeight;var vertices=d3.range(100).map(function(a){return[Math.random()*width,Math.random()*height]});var svg=d3.select(".footer").append("svg").attr("width",width).attr("height",height).attr("class","PiYG").on("mousemove",update);svg.selectAll("path").data(d3.geom.voronoi(vertices)).enter().append("path").attr("class",function(a,b){return b?"q"+b%9+"-9":null}).attr("d",function(a){return"M"+a.join("L")+"Z"});svg.selectAll("circle").data(vertices.slice(1)).enter().append("circle").attr("transform",function(a){return"translate("+a+")"}).attr("r",2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment