HTML5 canvas line example

HTML5 canvas lineto example. This example uses canvas path, line width, line style, line cap.

<canvas id="mycanvas1" width="200" height="100" 
style="border:1px solid green; background-color:lightgray;">
</canvas>
<script type="text/javascript">
window.addEventListener("load", draw);
function draw() {
  var canvas = document.querySelector('#mycanvas1');
  var context = canvas.getContext('2d');
  context.lineWidth = 10;
  context.strokeStyle="lightgreen";
  context.lineCap="round";
  context.beginPath();
  context.moveTo(20,10);
  context.lineTo(100,50);
  context.lineTo(100,70);
  context.stroke();
  context.closePath();
}
</script>
refresh

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments