Metode lineTo
Die metode lineTo trek 'n lyn van punt
tot punt. Die lyn word getrek vanaf die huidige posisie
van die tekenpen na die gespesifiseerde koördinate.
Koördinate word gespesifiseer deur die parameters van die metode.
Sintaksis
javascriptkonteks.lineTo(x, y);
Voorbeeld
Kom ons teken 'n lyn:
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.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.stroke();
Результат:
Voorbeeld
Kom ons teken 'n klein vierkant:
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.moveTo(50, 50);
ctx.lineTo(150, 50);
ctx.lineTo(150, 150);
ctx.lineTo(50, 150);
ctx.lineTo(50, 50);
ctx.stroke();
Результат: