Skip to content

Instantly share code, notes, and snippets.

@SamEureka
Last active January 7, 2016 17:45
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 SamEureka/d2bce08814d547c97524 to your computer and use it in GitHub Desktop.
Save SamEureka/d2bce08814d547c97524 to your computer and use it in GitHub Desktop.
D3 - SpiroSlinky
body {
margin: 0;
background: #222;
min-width: 960px;
}
rect {
fill: none;
pointer-events: all;
}
circle {
fill: none;
stroke-width: 1.5px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>D3 Spiro/Slinky</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"
<script src="index.js"></script>
</body>
</html>
var width = Math.max(960, innerWidth),
height = Math.max(500, innerHeight);
var i = 0;
var svg = d3.select("body").append("svg")
.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", 1)
.style('stroke-width', 0.2 * width)
.style("stroke", '#255FCC')
.style("stroke-opacity", 0.5)
.style("stroke", function(d) {
return "hsl(" + Math.random() * 360 + ",100%,50%)"
})
.transition()
.duration(2000)
.ease(Math.random)
.attr("r", 1)
.style("stroke-opacity", 1e-6)
.remove();
d3.event.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment