I am trying to generate a few images using canvas but I still see the previous image on the new one. I tried a few ways to clear images, but none of these works. What could be missing here:
const canvas = createCanvas(format.width, format.height);
const ctx = canvas.getContext("2d", {alpha: false});
for (attributes in attributesList) {
await Promise.all(loadedElements).then((renderObjectArray) => {
ctx.clearRect(0, 0, format.width, format.height);
ctx.beginPath(); // begin
//ctx.fillStyle = "white";
ctx.fillRect(0, 0, format.width, format.height);
renderObjectArray.forEach((renderObject) => {
drawElement(renderObject, attributes);
});
});
ctx.closePath(); // close
ctx.stroke();
saveImage();
}