I am trying to make a light weight progress bar using canvas. The target for this project is to have a progress bar filled to N percent from a given variable. For the purpose of this demo, I have manually set a 50% fill.
There are two colors: red which is filled by when loaded and green represents the progress completed.
How can I animate the progression of the green fill?
var canvas = document.getElementById('myProgress');
var myPerc = 500;
ctx = canvas.getContext('2d');
ctx.fillStyle = "rgb(255, 0, 0)";  //red
ctx.fillRect(0,0,myPerc,100);
ctx.save();
    for (var i=0;i<(myPerc*0.5);i++)
    { 
        ctx.fillStyle = "rgb(0, 255, 0)";  //green
            setTimeout(function() {
                    ctx.fillRect(0,0,+i,100);
            }, 1000);   
    }
 
     
    