I have one rectangle that I want to fill with green and red, as a health bar for a game.
ctx.beginPath();
ctx.rect(this.x+5, this.y-15, 30, 3); // this.x/y are class members
ctx.strokeStyle="#000000";
ctx.lineWidth=5;
ctx.stroke();
ctx.fillStyle="green";
ctx.fill();
ctx.closePath();
Now this will give me a purely green rectangle, how can I make it so x percent of the rectangle is green and the rest is red?
I would simply draw another rectangle on top of the red rectangle, and move the x position according to the hp.