Skip to content

Instantly share code, notes, and snippets.

@amundo
Forked from mbostock/.block
Created December 18, 2012 06:21
Show Gist options
  • Save amundo/4325543 to your computer and use it in GitHub Desktop.
Save amundo/4325543 to your computer and use it in GitHub Desktop.

Mouseover to make particles. Built with D3.js.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>OMG Particles!</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.25.0"></script>
<style type="text/css">
body {
background: #222;
}
circle {
fill: none;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<script type="text/javascript">
var w = 960,
h = 500,
z = d3.scale.category20c(),
i = 0;
var svg = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h)
.style("pointer-events", "all")
.on("mousemove", particle);
function particle() {
var m = d3.svg.mouse(this);
svg.append("svg:circle")
.attr("cx", m[0])
.attr("cy", m[1])
.attr("r", 1e-6)
.style("stroke", z(++i))
.style("stroke-opacity", 1)
.transition()
.duration(3000)
.ease(Math.sqrt)
.attr("r", 100)
.style("stroke-opacity", 1e-6)
.remove();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment