Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created January 29, 2013 04:06
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 tmcw/4661711 to your computer and use it in GitHub Desktop.
Save tmcw/4661711 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font:normal 12px/20px 'Georgia';
background:#222;
text-align:center;
}
circle {
fill:#ccc;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var g = d3.select('body').append('svg')
.attr({ width: 800, height: 800 })
.append('g')
.attr('transform', 'translate(400, 400) scale(0.25, 0.25)');
var r = 400;
function step() {
g.append('circle')
.transition()
.duration(1000)
.each('end', function() {
var w = Math.sqrt(Math.pow(r,2)*2);
g.append('rect').attr('class', 'p')
.attr({
width:w,
height:w,
x: -w/2,
y: -w/2
});
r *= 0.707105;
g.transition().attr('transform', 'translate(400, 400) scale(' + [100/r, 100/r] + ')');
if (r > 4) step();
})
.attr('r', r);
}
step();
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment