Last active
January 26, 2016 10:10
-
-
Save kraftner/d59ff5f45d8d178cf5e7 to your computer and use it in GitHub Desktop.
NoScript Debug Inside Animation
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
* { | |
margin:0; | |
padding:0; | |
} | |
path:first-child { | |
fill: #2d2d2a !important; | |
} | |
circle { | |
pointer-events: none; | |
} | |
path { | |
fill: rgba(255,255,255,0.1) | |
} | |
</style> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script> | |
var width = Math.max(960, innerWidth), | |
height = Math.max(500, innerHeight); | |
var vertices = d3.range(100).map(function(d) { | |
return [Math.random() * width, Math.random() * height]; | |
}); | |
var voronoi = d3.geom.voronoi() | |
.clipExtent([[0, 0], [width, height]]); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.on("mousemove", function() { vertices[0] = d3.mouse(this); redraw(); }); | |
var path = svg.append("g").selectAll("path"); | |
svg.selectAll("circle") | |
.data(vertices.slice(1)) | |
.enter().append("circle") | |
.attr("transform", function(d) { return "translate(" + d + ")"; }) | |
.attr("r", 1.5); | |
redraw(); | |
function redraw() { | |
path = path | |
.data(voronoi(vertices), polygon); | |
path.exit().remove(); | |
path.enter().append("path") | |
.attr("d", polygon); | |
path.order(); | |
} | |
function polygon(d) { | |
return "M" + d.join("L") + "Z"; | |
} | |
svg.on("click", function() { console.log('inside animation'); }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment