Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active September 12, 2018 12:58
Show Gist options
  • Save romsson/0a2c1c6ae60e1814d8edc1009062258f to your computer and use it in GitHub Desktop.
Save romsson/0a2c1c6ae60e1814d8edc1009062258f 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("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("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("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("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