Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active August 25, 2018 14:47
Show Gist options
  • Save romsson/d4d050786837cd71dc4b1155ef2c1f65 to your computer and use it in GitHub Desktop.
Save romsson/d4d050786837cd71dc4b1155ef2c1f65 to your computer and use it in GitHub Desktop.
multiple clippath olverapped SVG circles intersections
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var n = 4,
s = 100,
r = 50;
function pts(nb) {
var alpha = (2 * Math.PI) / nb,
res = [];
for(var i = 0; i < (2*Math.PI); i += alpha) {
res.push({
x: Math.cos(i),
y: Math.sin(i)
});
}
return res;
}
var color = d3.scaleOrdinal(d3.schemeCategory20);
var c = d3.scaleLinear()
.range([0, s])
.domain([-1, 1]);
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
svg.selectAll("circle").data(pts(n))
.enter()
.append("circle")
.attr("cx", function(d) { return c(d.x); })
.attr("cy", function(d) { return c(d.y); })
.attr("r", function(d) { return r; })
.style("fill", function(d, i) {
return color(i);
})
.style("stroke", "black")
.attr("transform", "translate(200, 200)")
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment