How to draw a line on the canvas with square line cap in JavaScript

1 Answer

0 votes
<canvas id="canvas"></canvas
<script type="text/JavaScript">   

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

ctx.beginPath();
ctx.moveTo(20, 20);
ctx.lineWidth = 17;
ctx.lineCap = "square";
ctx.lineTo(120, 120);
ctx.stroke();

/*
run:  
    
   
*/
  
</script>

 



answered May 24, 2016 by avibootz
...