block by mpmckenna8 fb377a58d046d98e8c76

fb377a58d046d98e8c76

Full Screen

Mouseover or touch on a touch device to make particles. Built with D3.js. Based on Mike Bostock’s original.

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>OMG Particles!</title>
<script src="//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>