Built with blockbuilder.org
Created
October 21, 2018 02:55
-
-
Save jwilber/abf998e3e793a7e34a5fba5cc64a1045 to your computer and use it in GitHub Desktop.
flubber rect demo
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://unpkg.com/flubber@0.3.0"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<svg width="960" height="500"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v3.min.js"></script> | |
<script src="https://unpkg.com/flubber@0.3.0"></script><script> | |
var svg = d3.select("svg"), | |
path = svg.append("path"); | |
d3.json("lower48.topo.json", function(err, topo) { | |
var states = topojson | |
.feature(topo, topo.objects.states) | |
.features.map(d => d.geometry.coordinates[0]); | |
d3.shuffle(states); | |
draw(0); | |
function draw(i) { | |
var start = states[0], | |
next = states[1], | |
height = 250, | |
width = 80 + i % 3 * 80, | |
x = 120 + i % 2 * 600, | |
y = 125; | |
var outward = flubber.toRect(start, x, y, width, height, { maxSegmentLength: 10 }), | |
inward = flubber.fromRect(x, y, width, height, next, { maxSegmentLength: 10 }); | |
states.push(states.shift()); | |
path | |
.attr("d", "M" + start.join("L") + "Z") | |
.transition() | |
.delay(600) | |
.duration(2000) | |
.attrTween("d", () => outward) | |
.transition() | |
.delay(600) | |
.attrTween("d", () => inward) | |
.on("end", () => draw(i + 1)); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment