Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active September 12, 2018 13:56
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/9d3c2c0522757d9e079ad121ad87a59e to your computer and use it in GitHub Desktop.
Save romsson/9d3c2c0522757d9e079ad121ad87a59e to your computer and use it in GitHub Desktop.
circle overlaps intersection clipping
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 color0 = d3.scaleLinear()
.domain([0, 1])
.range(['white', 'red'])
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
svg
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 150)
.style("fill", "none")
.style("stroke", "black")
// .style("fill", "red")
.style("opacity", .1);
svg.append("clipPath")
.attr("id", "circle-clip-1-1")
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 150)
.style("fill", "red")
.style("opacity", .1);
svg
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 130)
.style("stroke", "black")
.style("fill", "none")
.style("opacity", .1);
svg.append("clipPath")
.attr("id", "circle-clip-1-2")
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 130)
.style("fill", "red")
.style("opacity", .1);
svg
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 110)
.style("fill", "red")
.style("opacity", .1);
svg.append("clipPath")
.attr("id", "circle-clip-1-3")
.append("circle")
.attr("cy", 150)
.attr("cx", 150)
.attr("r", 110)
.style("fill", "red")
.style("opacity", .1);
// circle 2
svg
.append("circle")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("stroke", "black")
.style("fill", "none")
.style("opacity", .1);
svg.append("clipPath")
.attr("id", "circle-clip-2-1")
.append("circle")
.attr("clip-path","url(#circle-clip-1-1)")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("fill", "red")
.style("opacity", .1);
svg
.append("circle")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 130)
.style("stroke", "black")
.style("fill", "none")
.style("opacity", .1);
svg.append("clipPath")
.attr("id", "circle-clip-2-2")
.append("circle")
.attr("clip-path","url(#circle-clip-1-2)")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 130)
.style("fill", "red")
.style("opacity", .1);
svg
.append("circle")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 110)
.style("fill", "red")
.style("opacity", .1);
// circle 3
//svg.append("circle")
// .attr("cy", 200)
// .attr("cx", 350)
// .attr("r", 150)
// .style("fill", "green")
// .style("opacity", 1);
svg.append("circle")
.attr("clip-path","url(#circle-clip-2-1)")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("fill", "red")
.style("opacity", 1);
svg.append("circle")
.attr("clip-path","url(#circle-clip-2-2)")
.attr("cy", 300)
.attr("cx", 250)
.attr("r", 150)
.style("fill", "red")
.style("opacity", 1);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment