Created
September 28, 2012 18:32
-
-
Save jasondavies/3801416 to your computer and use it in GitHub Desktop.
Clipping Self-Intersections
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> | |
<style> | |
path { | |
stroke: #ccc; | |
fill: none; | |
} | |
path.clip { | |
stroke: #fff; | |
fill: #fc0; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var polygon = { | |
type: "Polygon", | |
coordinates: [[ | |
[-30, -30], | |
[-30, 30], | |
[ 10, -10], | |
[-20, 10], | |
[-20, -20], | |
[ 20, -20], | |
[ 20, 10], | |
[-10, -10], | |
[ 30, 30], | |
[ 30, -30], | |
[-30, -30] | |
]] | |
}; | |
var path = d3.geo.path().projection(d3.geo.mercator().translate([width / 2, height / 2]).scale(width)); | |
var svg = d3.select("body").append("svg"); | |
svg.append("path") | |
.datum(polygon) | |
.attr("d", path); | |
var circle = d3.geo.circle().origin([0, -90]); | |
var clipPath = svg.append("path").attr("class", "clip"); | |
d3.timer(function(elapsed) { | |
clipPath | |
.datum(circle.angle(45 + elapsed / 100).clip(polygon)) | |
.attr("d", path); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment