การเปลี่ยนขนาดเส้นใน Canvas บน JavaScript
ความหนาของเส้นถูกกำหนดโดยใช้คุณสมบัติ
lineWidth แค่กำหนดความหนาให้มัน,
ตัวอย่างเช่น: lineWidth = 5 - จะได้
ความหนาของเส้น 5px ลองดูตัวอย่าง:
<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 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();
: