I have a concentric circle in SVG in HTML but I would like the bottom half to look like the top half. The bottom has the circles are misaligned.
const svgNs = "http://www.w3.org/2000/svg";
let svg = document.querySelector("svg");
function drawHalfCircle(x, y, r, sweepFlag, width) {
let path = document.createElementNS(svgNs, "path");
let xStart = x - r;
let xEnd = x + r;
let command = `M ${xStart} ${y} A ${r} ${r} 0 0 ${sweepFlag} ${xEnd} ${y}`;
path.setAttribute("d", command);
path.setAttribute("stroke", "#627ca9");
path.setAttribute("fill", "none");
path.setAttribute("stroke-width", width.toString());
svg.appendChild(path);
}
let width = 10;
let nrOfCircles = 1000 / width / 2 - 2;
for(let i = 0; i < nrOfCircles; i++) {
let r = width + i * width;
let sweepFlag = i % 2;
drawHalfCircle(500, 500, r, sweepFlag, width);
}
html, body {
height: 100%;
margin: 0;
}
svg {
position: absolute;
width: 100%;
height: 100%;
}
<svg viewBox="0 0 1000 1000" >
</svg>
I'm new to Javascript, I tweaked the settings but couldn't get to the solution.
Thank you in advance. Sorry my english.