Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active September 24, 2018 15:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/2472e84f78fd03df443f to your computer and use it in GitHub Desktop.
Save mbostock/2472e84f78fd03df443f to your computer and use it in GitHub Desktop.
Spiral Circle
license: gpl-3.0
redirect: https://beta.observablehq.com/@mbostock/spiral-stack
<!DOCTYPE html>
<meta charset="utf-8">
<style>
rect {
fill: #fff;
stroke: #000;
stroke-width: .7px;
}
</style>
<svg width="960" height="500">
<defs>
<clipPath id="clip-upper">
<rect width="960" height="250" x="-480" y="-250"></rect>
</clipPath>
<clipPath id="clip-lower">
<rect width="960" height="250" x="-480" y="0"></rect>
</clipPath>
</defs>
<g clip-path="url(#clip-upper)" transform="translate(480,250)"></g>
<g clip-path="url(#clip-lower)" transform="translate(480,250)"></g>
</svg>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500,
circleRadius = 180,
squareCount = 200,
squareSize = 78,
speed = .08;
var square = d3.selectAll("g")
.append("g")
.attr("transform", function(d, i) { return i ? "rotate(180)" : null; })
.selectAll("rect")
.data(d3.range(squareCount))
.enter().append("rect")
.datum(function(i) { return i / squareCount; })
.attr({width: squareSize, height: squareSize, x: -squareSize / 2, y: -squareSize / 2});
d3.timer(function(elapsed) {
square
.attr("transform", function(t) { return "rotate(" + (t * 360) + ")translate(0," + circleRadius + ")rotate(" + (t * 360 + elapsed * speed) + ")"; });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment