How To Draw Circle Animation Not Using Canvas?
I have a background image, and a div child in which I draw a circle. Here some sample code http://codepen.io/anon/pen/hybAs . I want to be able to 'erase' this circle like (source
Solution 1:
Just using the svg path to create an arc. I found the arc creating sample here: How to calculate the SVG Path for an arc (of a circle)
Now just iterate from 0 to 360 degree angle to create the arc using setInterval as below:
<svgxmlns="http://www.w3.org/2000/svg"height="1300"width="1600"viewBox="0 0 1600 1300"id="star-svg"><pathid="arc1"fill="none"stroke="yellow"stroke-width="50" /></svg><scripttype="text/javascript">var a = document.getElementById("arc1");
var i =1;
var int = setInterval(function() {
if (i>360) { clearInterval(int); return;};
a.setAttribute("d", describeArc(200, 200, 25, 0, i));
i++;
}, 10);
functionpolarToCartesian(centerX, centerY, radius, angleInDegrees) {
var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians))
};
}
functiondescribeArc(x, y, radius, startAngle, endAngle){
var start = polarToCartesian(x, y, radius, endAngle);
var end = polarToCartesian(x, y, radius, startAngle);
var arcSweep = endAngle - startAngle <= 180 ? "0" : "1";
var d = [
"M", start.x, start.y,
"A", radius, radius, 0, arcSweep, 0, end.x, end.y
].join(" ");
return d;
}
</script>
Post a Comment for "How To Draw Circle Animation Not Using Canvas?"