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 n = 4, | |
s = 100, | |
r = 50; | |
function pts(nb) { | |
var alpha = (2 * Math.PI) / nb, | |
res = []; | |
for(var i = 0; i < (2*Math.PI); i += alpha) { | |
res.push({ | |
x: Math.cos(i), | |
y: Math.sin(i) | |
}); | |
} | |
return res; | |
} | |
var color = d3.scaleOrdinal(d3.schemeCategory20); | |
var c = d3.scaleLinear() | |
.range([0, s]) | |
.domain([-1, 1]); | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 500) | |
svg.selectAll("circle").data(pts(n)) | |
.enter() | |
.append("circle") | |
.attr("cx", function(d) { return c(d.x); }) | |
.attr("cy", function(d) { return c(d.y); }) | |
.attr("r", function(d) { return r; }) | |
.style("fill", function(d, i) { | |
return color(i); | |
}) | |
.style("stroke", "black") | |
.attr("transform", "translate(200, 200)") | |
</script> | |
</body> |