refresh the canvas after x seconds - Javascript Canvas Reference

Javascript examples for Canvas Reference:clearRect

Description

refresh the canvas after x seconds

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
          Your browser does not support the HTML5 canvas tag. 
      </canvas> 
      <script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);//w w  w  . j a v a  2s.c  om
setInterval(function(){
  ctx.clearRect(0, 0, c.width, c.height);
  console.log("Canvas cleared");
},
3000);

      </script>  
   </body>
</html>

Related Tutorials