Hi there I am going crazy (my wife says it will be a short trip!) I have just started with Canvas and I cannot get the canvas to show intermediate results. I have read many articles here but those articles refer to all kinds of "things" and nothing to the basics. Here is the code:
<!DOCTYPE html>
<html>
<body>
<canvas id="RoomCanvas" width="300" height="200">
<!-- ************************************* -->
<!-- The wall is always here -->
<!-- ************************************* -->
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
var c = document.getElementById("RoomCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, 300, 200);
alert("clear");
doWall("green");
alert("try");
ctx.clearRect(0, 0, 300, 200);
alert("wall");
doWall("purple");
function doWall(theColor){
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(0, 200);
ctx.closePath();
ctx.lineWidth = 44;
ctx.strokeStyle = theColor;
ctx.stroke();
return;
}
</script>
</body>
</html>
var c = document.getElementById("RoomCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, 300, 200);
alert("clear");
doWall("green");
alert("try");
ctx.clearRect(0, 0, 300, 200);
alert("wall");
doWall("purple");
function doWall(theColor) {
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(0, 200);
ctx.closePath();
ctx.lineWidth = 44;
ctx.strokeStyle = theColor;
ctx.stroke();
return;
}
<!DOCTYPE html>
<html>
<body>
<canvas id="RoomCanvas" width="300" height="200">
<!-- ************************************* -->
<!-- The wall is always here -->
<!-- ************************************* -->
Your browser does not support the HTML5 canvas tag.
</canvas>
</body>
</html>
The green line never shows. The canvas only "shows" when the program stops running. I have tried to take superfluous code out of the example. Basically I want the program to draw three lines. When the fourth line is drawn I want to erase line 1. My problem no lines show until the program quits and then only the last 3 lines show, the user never sees any other lines.
Thank you, your help will be appreciated.