Mouseover or touch on a touch device to make particles. Built with D3.js. Based on Mike Bostock’s original.
-
-
Save mpmckenna8/fb377a58d046d98e8c76 to your computer and use it in GitHub Desktop.
This file contains 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"> | |
<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