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