let input = 0;
const overlay = document.getElementById("overlay");
const text = document.getElementById("text");
function converter(input) {
if(input > 1000) input = 1000;
const percentage = input / 1000;
let stage = percentage < .125 ? 1 :
percentage < .25 ? 2 :
percentage < .375 ? 3 :
percentage < .5 ? 4 :
percentage < .625 ? 5 :
percentage < .75 ? 6 :
percentage < .875 ? 7 : 8
const clipPath = {
1: `polygon(0% 0%, 50% 0%, 50% 50%,${(percentage/.125 * 50) + 50}% 0%, 100% 0%, 100% 100%, 0% 100%)`,
2: `polygon(0% 0%, 50% 0%, 50% 50%, 100% ${((percentage-.125)/.125 * 50)}%, 100% 100%, 0% 100%)`,
3: `polygon(0% 0%, 50% 0%, 50% 50%, 100% ${((percentage-.25)/.125 * 50) + 50}%, 100% 100%, 0% 100%)`,
4: `polygon(0% 0%, 50% 0%, 50% 50%, ${100-((percentage-.375)/.125 * 50)}% 100%, 0% 100%)`,
5: `polygon(0% 0%, 50% 0%, 50% 50%, ${50-((percentage-.5)/.125 * 50)}% 100%, 0% 100%)`,
6: `polygon(0% 0%, 50% 0%, 50% 50%, 0% ${100-((percentage-.625)/.125 * 50)}%)`,
7: `polygon(0% 0%, 50% 0%, 50% 50%, 0% ${50-((percentage-.75)/.125 * 50)}%)`,
8: `polygon(0% 0%, 50% 0%, 50% 50%, ${((percentage-.875)/.125 * 50)}% 0% )`,
}[stage]
overlay.style.clipPath = clipPath;
text.textContent = `${Math.round(percentage * 100)}%`
}
const interval = setInterval(() => {
converter(input)
if(input === 1000) {
clearInterval(interval);
const inputEle = document.createElement("input");
inputEle.setAttribute("type","number");
inputEle.setAttribute("id","input");
const submitEle = document.createElement("input");
submitEle.setAttribute("type","submit");
submitEle.setAttribute("value","submit");
submitEle.onclick = () => converter(document.getElementById("input").value);
document.body.append(inputEle);
document.body.append(submitEle);
}
input += 1;
}, 1);
#container {
margin-bottom: 16px;
}
#circle {
width: 120px;
height: 120px;
border-radius: 120px;
background-color: black;
border: 8px solid lightblue;
box-sizing: border-box;
}
#overlay {
position: absolute;
width: 120px;
height: 120px;
border-radius: 120px;
border: 8px solid dimgray;
box-sizing: border-box;
}
#text {
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
height: 120px;
width: 120px;
text-align: center;
color: white;
font-size: 24px;
}
<div id="container">
<div id="text">0%</div>
<div id="overlay"></div>
<div id="circle"></div>
</div>