Skip to content
Advertisement

SVG: how to draw multiple semicircles (arcs) path

Using the answer from this thread I was able to draw a semicircle (arc):

JavaScript
JavaScript

What I’m trying to achieve is to be able to draw an SVG as a path consistent with many arcs (semicircles) and be able to set fill on them.

Something like this: enter image description here

JavaScript

Is there a better way to achieve a simpler path? For now, it looks like this:

JavaScript

Or do I have to generate a longer and longer path when there are, let’s say, 30 semicircles?

Edit: the IE9+ support is required. Also, those elements will be clickable, draggable and controllable. By controllable I mean that their number and size will change when mouse clicking/moving.

I choose my first approach with a dynamic very long path.

Thanks!

Advertisement

Answer

For this I would use lower case commands. For example this is drawing the arc you need: an arc with a radius of 25 and an ending point 50 units ( 2 * 25 ) away from the starting point of the arc.

JavaScript

In order to get a path of 4 arcs you need to repeat the arc (a 25 25 0 0 1 50 0) 4 times something like this:

JavaScript

It’s easy to see how you can use javascript to generate the d attribute you need:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement