Doing Infix to PostFix Stack Implementation using HTML5 canvas. The desired output is, element box in the canvas must have to output every character for 1 sec and then fade away. While the problem is element box in the canvas is updating after the code execution finished, which results in overlapping of all the character in the canvas element box and then fading out after 1 sec.
Please have a look at the code below:
function convert(e){ // when convert button click
var x = document.getElementById('infix').value;
var stack = new Stack();
stack.postFix(x);
}
function elementVisualize(ele){
var eleVis = canvas.getContext('2d');
eleVis.fillText(ele,150,150);
console.log(ele);
setTimeout(function(){
eleVis.clearRect(100,80,148,148);
}, 1000);
}
postFix(exp){ // Stack.postFix function
for(var i = 0; i < exp.length ; i++){
var c = exp[i];
if((c>='0' && c<='9') || (c>='A' && c<='Z') || (c>='a' && c<='z')){
elementVisualize(c);
}
}
}
is their anyway to update the canvas for each character separately ?