Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active August 27, 2018 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romsson/d978f41607f968397ec200a1384952f6 to your computer and use it in GitHub Desktop.
Save romsson/d978f41607f968397ec200a1384952f6 to your computer and use it in GitHub Desktop.
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 svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
svg.append("clipPath")
.attr("id", "circle-clip")
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 150)
.style("fill", "red")
.style("opacity", .2);
svg
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 150)
.style("fill", "red")
.style("opacity", 1);
svg
.append("circle")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("fill", "yellow")
.style("opacity", 1);
svg.append("circle")
.attr("cy", 200)
.attr("cx", 350)
.attr("r", 150)
.style("fill", "green")
.style("opacity", 1);
svg.append("clipPath")
.attr("id", "circle-clip2")
.append("circle")
.attr("clip-path","url(#circle-clip)")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("fill", "yellow")
.style("opacity", 1);
svg.append("circle")
.attr("clip-path","url(#circle-clip2)")
.attr("cy", 200)
.attr("cx", 350)
.attr("r", 150)
.style("fill", "blue")
.style("opacity", 1);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment