lineWidth 속성
lineWidth 속성은 canvas에서 그릴 때
선의 두께를 지정합니다.
구문
컨텍스트.lineWidth = 정수;
예제
5픽셀 두께로 선을 그려봅시다:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.lineWidth = 5; // 두께 5px
ctx.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.stroke();
:
예제
두께는 rect와 같이
그린 윤곽선에 대해서도 변경할 수 있습니다:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
ctx.rect(50, 50, 100, 100);
ctx.lineWidth = 5;
ctx.stroke();
: