A partial recreation of a mesmerizing (and topologically impossible!) untitled GIF by PATAKK.
Last active
August 5, 2020 20:35
-
-
Save mbostock/1d48ce4f3024edfc2277 to your computer and use it in GitHub Desktop.
Spiral Triangle
This file contains hidden or 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
license: gpl-3.0 |
This file contains hidden or 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> | |
rect { | |
fill: #fff; | |
stroke: #000; | |
} | |
</style> | |
<svg width="960" height="500"> | |
<defs> | |
<clipPath id="clip-upper"> | |
<rect width="960" height="305" x="-480" y="-305"></rect> | |
</clipPath> | |
<clipPath id="clip-lower"> | |
<rect width="960" height="195" x="-480" y="0"></rect> | |
</clipPath> | |
</defs> | |
<g clip-path="url(#clip-upper)" transform="translate(480,305)"></g> | |
<g clip-path="url(#clip-lower)" transform="translate(480,305)"></g> | |
</svg> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500, | |
triangleSize = 400, | |
squareCount = 71, | |
squareSize = 90, | |
speed = .08; | |
var square = d3.selectAll("g") | |
.selectAll("g") | |
.data(function(d, i) { return i ? [0, 1, 2] : [2, 0, 1]; }) | |
.enter().append("g") | |
.attr("transform", function(i) { return "rotate(" + (i * 120 + 60) + ")translate(0," + -triangleSize / Math.sqrt(12) + ")"; }) | |
.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 "translate(" + (t - .5) * triangleSize + ",0)rotate(" + (t * 120 + elapsed * speed) + ")"; }); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment