Skip to content

Instantly share code, notes, and snippets.

@muratabur
Last active September 8, 2015 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muratabur/2f1629e5aa76cc3f41b8 to your computer and use it in GitHub Desktop.
Save muratabur/2f1629e5aa76cc3f41b8 to your computer and use it in GitHub Desktop.
Gist101: a bunch of random circles

This is my first gist-bl.ock-ing attempt, let;s see how it goes...

<!DOCTYPE html>
<meta charset="utf-8">
<style>
rect {
fill: none;
pointer-events: all;
}
circle {
fill: none;
stroke-width: 2.5px;
}
</style>
<svg width="960" height="500" id="chart"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<script type="text/javascript">
// requires d3.js
// define visualisation
var width = "100%"
height = "100%"
var i = 0;
var svg = d3.select("#chart").append("svg") // visualisation id
.attr("width", width)
.attr("height", height);
svg.append("rect")
.attr("width", width)
.attr("height", height)
.on("ontouchstart" in document ? "touchmove" : "mousemove", particle);
function particle() {
var m = d3.mouse(this);
svg.insert("circle", "rect")
.attr("cx", m[0])
.attr("cy", m[1])
.attr("r", 1e-6)
.style("stroke", d3.hsl((i = (i + 1) % 360), 1, .5))
.style("stroke-opacity", 1)
.transition()
.duration(4000)
.ease(Math.sqrt)
.attr("r", 400)
.style("stroke-opacity", 1e-6)
.remove();
d3.event.preventDefault();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment