线段两端的样式

lineCap = ‘butt/squa**re/round’
线段两端的样式
butt **默认样式

  1. <canvas id="canvas" width="500" height="500" style="width: 500px; height: 500px; border: 1ex solid black;"></canvas>
  2. <script>
  3. var canvas = document.getElementById('canvas');
  4. var ctx = canvas.getContext('2d');
  5. ctx.beginPath();
  6. ctx.lineWidth = 15;
  7. ctx.moveTo(100,100);
  8. ctx.lineTo(200,100)
  9. ctx.lineCap = 'butt'; // square 线段末端以方形结束,会为其添加一个正方形 round 线段末端以圆形结束
  10. ctx.stroke()
  11. </script>

效果
butt 默认样式 square 线段末端以方形结束,会为其**两端添加一个正方形 round 线段末端以圆形结束**
image.png image.png image.png

线段相交的样式

lineJoin = ‘miter/rou**nd/bevel’
两线相交后的样式
miterLimit = num**ber
两线相交从何**处截断**

  1. <canvas id="canvas" width="500" height="500" style="width: 500px; height: 500px; border: 1ex solid black;"></canvas>
  2. <script>
  3. var canvas = document.getElementById('canvas');
  4. var ctx = canvas.getContext('2d');
  5. ctx.beginPath();
  6. ctx.lineWidth = 15;
  7. ctx.moveTo(100,100);
  8. ctx.lineTo(200,100)
  9. ctx.lineTo(100,150);
  10. ctx.lineJoin = 'miter' //round 两线相交一圆形结束 bevel 两线相交截断
  11. ctx.miterLimit = 5; // 两线相交从何处截断
  12. ctx.stroke()
  13. </script>

miter 默认样式 bevel 两线相**交截断 round 两线相交以圆形结束
image.png image.png image.png
miterLimit 两线相交从何处截断**

  1. <canvas id="canvas" width="500" height="500" style="width: 500px; height: 500px; border: 1ex solid black;"></canvas>
  2. <script>
  3. var canvas = document.getElementById('canvas');
  4. var ctx = canvas.getContext('2d');
  5. ctx.beginPath();
  6. ctx.lineWidth = 15;
  7. ctx.moveTo(100,100);
  8. ctx.lineTo(200,100)
  9. ctx.lineTo(100,150);
  10. ctx.miterLimit = 3; // 两线相交从何处截断
  11. ctx.stroke()
  12. </script>

正常情况 ctx.miterLi**mit = 3
image.png image.png**