HTML Canvas clearRect() clear after drawing

Description

HTML Canvas clearRect() clear after drawing

View in separate window

<!DOCTYPE html>
<html>
<body>

<canvas id="canvas" width="640" height="280" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>
      let theCanvas = document.getElementById('canvas');
      let context = theCanvas.getContext('2d');

    context.fillStyle   = '#000000'; 
    context.strokeStyle = '#ff00ff'; 
    context.lineWidth   = 2;//from   www .  j  a va  2  s .c om
    context.fillRect(10,10,40,40);
    context.strokeRect(0,  0, 60, 60);
    context.clearRect(20,20,20,20);

</script>

</body>
</html>



PreviousNext

Related