I am trying to progressively fill an ellipse behind a rotating radius, really, a clock-like timer that fills behind the sweeping hand. I am close to getting it right but the arc of the filled area moves with each recalculation.
The CodePen version is here but to summarize, I am using the following HTML to start:
<svg version="1.1" baseProfile="full" width="50%" height="50%" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 3.2">
<path id="pie" stroke="none" stroke-width=".01" fill="rgb(204, 50, 50)"
d="M 1.5 1.7 V 1.5 .3
A 1.5 1.3 0 0 1 1.5 .2
z"/>
<line id="hand" stroke="black" stroke-width=".02"
x1="1.5" y1="1.7" x2="1.5" y2=".2"/>
</svg>
and the following JavaScript to rotate the hand and draw/fill behind it:
var sweep = document.getElementById("hand"),
fill = document.getElementById("pie"),
degrees = 0;
const Torads = Math.PI/180;
function rotateHand() {
degrees += 45;
sweep.setAttribute("transform", "rotate(" + degrees + " 1.5 1.7)");
if (degrees <= 180) {
fill.setAttribute("d", "M 1.5 1.7 V .4 A 1.4 1.3 0 0 1 " + ellipticalXcoords(Math.cos((degrees-90) * Torads)) + " " + ellipticalYcoords(Math.sin((degrees-90) * Torads)) + " z");
} else {
fill.setAttribute("d", "M 1.5 1.7 V .4 A 1.4 1.3 0 1 1 " + ellipticalXcoords(Math.cos((degrees - 90) * Torads)) + " " + ellipticalYcoords(Math.sin((degrees - 90) * Torads)) + " z");
}