svg of a circle with 10 smaller circles inside of it in typescript

To create an SVG circle with 10 smaller circles inside of it in TypeScript, you can first create a SVG container and set its dimensions to hold the circle and the nested circles. Then, you can create a circle element and nest it inside the SVG container. After that, you can use a for loop to create the 10 smaller circles inside of the larger circle by adjusting their positions relative to the center of the larger circle.

Here's an example code snippet to illustrate the process:

index.ts
const SVG_NS = "http://www.w3.org/2000/svg";
const svgContainer = document.createElementNS(SVG_NS, "svg");
svgContainer.setAttribute("width", "200");
svgContainer.setAttribute("height", "200");
document.body.appendChild(svgContainer);

const circle = document.createElementNS(SVG_NS, "circle");
circle.setAttribute("cx", "100");
circle.setAttribute("cy", "100");
circle.setAttribute("r", "80");
circle.setAttribute("fill", "none");
circle.setAttribute("stroke", "black");
svgContainer.appendChild(circle);

const numCircles = 10;
for (let i = 0; i < numCircles; i++) {
  const smallerCircle = document.createElementNS(SVG_NS, "circle");
  const angle = (2 * Math.PI * i) / numCircles;
  const x = 100 + 80 * Math.cos(angle);
  const y = 100 + 80 * Math.sin(angle);
  smallerCircle.setAttribute("cx", x.toString());
  smallerCircle.setAttribute("cy", y.toString());
  smallerCircle.setAttribute("r", "10");
  smallerCircle.setAttribute("fill", "blue");
  svgContainer.appendChild(smallerCircle);
}
997 chars
27 lines

In this example, the SVG container is created with a width and height of 200 pixels. The larger circle is positioned at the center of the container with a radius of 80 pixels and a black stroke. The nested circles are created using a for loop that calculates their positions around the center of the larger circle using trigonometry. The smaller circles have a radius of 10 pixels and are filled with blue color.

Note that you can use this code as a starting point and adjust the values as needed to fit your specific requirements.

gistlibby LogSnag