lineJoinプロパティ

プロパティlineJoinは、2本の線の接合方法を指定します。 次の値を取ることができます: miter - 鋭角(デフォルト)、 round - 丸められた角、bevel - 平らな角。

構文

javascriptcontext.lineJoin = 'miter' または 'round' または 'bevel';

例

プロパティlineJoinを値miterに設定します:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
  
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'miter';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();

Результат:

例

プロパティlineJoinを値roundに設定します:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
  
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'round';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();

Результат:

例

プロパティlineJoinを値bevelに設定します:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
  
ctx.beginPath();
ctx.lineWidth = 10;
ctx.lineJoin = 'bevel';
ctx.moveTo(50, 140);
ctx.lineTo(100, 30);
ctx.lineTo(150, 140);
ctx.stroke();

Результат:

関連項目

  • 鋭角の長さを制限するプロパティ miterLimit、
  • 線の端の形状を指定するプロパティ lineCap、