Created
January 29, 2013 04:10
-
-
Save tmcw/4661722 to your computer and use it in GitHub Desktop.
Inscribed circles, prettier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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') | |
.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); | |
var rect = g.append('rect').attr('class', 'p') | |
.attr({ | |
width:w, | |
height:w, | |
x: -w/2, | |
y: -w/2 | |
}); | |
rect.transition() | |
.attr('transform', 'rotate(' + Math.random() * 180 + ')'); | |
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