Draw line on canvas with moveTo and lineTo - Javascript Canvas Reference

Javascript examples for Canvas Reference:moveTo

Description

Draw line on canvas with moveTo and lineTo

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  www .  j  av a  2  s  .  c o m
var c=document.getElementById("myCanvas");
 var ctx=c.getContext("2d");
 ctx.moveTo(0,0);
 ctx.lineTo(400,200);
 ctx.moveTo(0,100);
 ctx.lineTo(400,100);
 ctx.stroke();
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myCanvas" width="400" height="400" style="border:0px solid #d3d3d3;">  
      </canvas>
   </body>
</html>

Related Tutorials