Built with blockbuilder.org
forked from romsson's block: detect olverapped SVG elements intersections
license: mit |
Built with blockbuilder.org
forked from romsson's block: detect olverapped SVG elements intersections
<!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> |