Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from mbostock/.block
Created May 8, 2012 08:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasondavies/2633501 to your computer and use it in GitHub Desktop.
Save jasondavies/2633501 to your computer and use it in GitHub Desktop.
OMG Particles! (D3)
<!DOCTYPE html>
<meta charset="utf-8">
<title>OMG Particles!</title>
<script src="http://mbostock.github.com/d3/d3.v2.min.js?2.9.1"></script>
<style>
body {
background: #222;
}
circle {
fill: none;
stroke-width: 1.5px;
}
</style>
<body>
<script>
var w = 960,
h = 500,
z = d3.scale.category20c(),
i = 0;
var svg = d3.select("body")
.on("touchstart", function() { d3.event.preventDefault(); })
.append("svg")
.attr("width", w)
.attr("height", h)
.style("pointer-events", "all")
.on("mousemove", function() { particle(d3.mouse(this)); })
.on("touchmove", function() { d3.touches(this).forEach(particle); });
function particle(m) {
svg.append("circle")
.attr("cx", m[0])
.attr("cy", m[1])
.attr("r", 1e-6)
.style("stroke", z(++i))
.style("stroke-opacity", 1)
.transition()
.duration(2000)
.ease(Math.sqrt)
.attr("r", 100)
.style("stroke-opacity", 1e-6)
.remove();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment