HTML5 Canvas: position of drawing cursor - Javascript Canvas

Javascript examples for Canvas:Draw

Description

HTML5 Canvas: position of drawing cursor

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/*from   w  ww. ja  va  2 s.co m*/
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(100,0);
ctx.lineTo(50,100);
ctx.closePath(); // makes the last line for you
ctx.stroke();
ctx.translate(175, 175);
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(100,0);
ctx.lineTo(50,100);
ctx.closePath(); // makes the last line for you
ctx.stroke();
    });

      </script> 
   </head> 
   <body> 
      <canvas id="canvas1" width="500" height="500"></canvas>  
   </body>
</html>

Related Tutorials