dynamic updating of HTML5 canvas - Javascript Canvas

Javascript examples for Canvas:Example

Description

dynamic updating of HTML5 canvas

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#one {// w w  w. j a v a2s . c o m
   top: 100px;
   left: 100px;
   position: absolute;
   width: 300px;
   height: 300px;
   background: #0b426b;
   border-radius: 100%;
}
#two {
   top: 15px;
   left: 15px;
   position: relative;
   width: 270px;
   height: 270px;
   background: -webkit-linear-gradient(top, #0a3453, #071a28);
   border-radius: 100%;
}
#myCanvas {
   position: absolute;
   z-index: 1;
}
body {
   background: papayawhip;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var endAngle = 1.5 * Math.PI; //startAngle=0;
var startAngle = 270;
window.setInterval(animate, 1000);
function animate(){
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.beginPath();
  ctx.arc(canvas.width / 2, canvas.height / 2, 143, Math.PI * 2 * startAngle / 360, endAngle);
  ctx.strokeStyle = "white";
  ctx.lineWidth = 14;
  ctx.stroke();
  console.log(startAngle);
  startAngle = (startAngle + 6) % 360;
}
    }

      </script> 
   </head> 
   <body>   
      <title>canvas</title> 
      <link rel="stylesheet" href="index.css">   
      <div id="one"> 
         <canvas id="myCanvas" height="300" width="300"></canvas> 
         <div id="two"></div> 
      </div>  
      <script src="index.js"></script>   
   </body>
</html>

Related Tutorials