9
I’m using an SVG circle and I want to share it with a line dynamically created into 12 parts. I can only divide into 4 parts, through its radius. I know it is possible through the sin
and cos
.
Example jsfiddle: https://jsfiddle.net/k3epungk/
Source code:
//raio circulo
r=50;
var circle = document.getElementById("circle");
circle.setAttribute("cx",100);
circle.setAttribute("cy",100);
circle.setAttribute("r",r);
//posiçao
x=100;
y=100;
var array_y1=[(y - r)+10,y,(y + r)+10,y];
var array_y2=[(y - r)-10,y,(y + r)-10,y];
var array_x1=[x,(x + r)+10,x,(x - r)+10];
var array_x2=[x,(x + r)-10,x,(x - r)-10];
var svg = document.getElementById('svg');
for(var i=0;i<=3;i++){
var newLine = document.createElementNS('http://www.w3.org/2000/svg','line');
newLine.setAttributeNS(null,'id','line'+i);
newLine.setAttributeNS(null,'x1',array_x1[i]);
newLine.setAttributeNS(null,'y1',array_y1[i]);
newLine.setAttributeNS(null,'x2',array_x2[i]);
newLine.setAttributeNS(null,'y2',array_y2[i]);
newLine.setAttributeNS(null,"stroke","black");
newLine.setAttributeNS(null,"stroke-width","1");
svg.appendChild(newLine);
}
<svg width=200 height=200 id=svg>
<circle id="circle" title="horloge" cx="100" cy="100" r="50" stroke-width="2px" fill="Aqua" stroke="black" />
</svg>
Thank you, it works perfectly. I wanted only the 4 central strokes to be slightly larger than the others.
– akm
@akm Edited. Is that how you want it? Or would it be larger in a matter of length rather than thickness?
– Victor Stafusa
That’s right, thank you
– akm