Metode beginPath
Die metode beginPath moet geroep word
aan die begin van die tekening van 'n lyn deur kombinasies
van die metodes moveTo
en lineTo te gebruik.
Sintaksis
konteks.beginPath();
Voorbeeld
Kom ons teken 'n lyn:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let 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 vierkantjie:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
let 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.closePath();
ctx.stroke();
: