Methode beginPath
Die Methode beginPath muss
zu Beginn der Zeichnung einer Linie mit Kombinationen
der Methoden moveTo
und lineTo aufgerufen werden.
Syntax
Kontext.beginPath();
Beispiel
Lassen Sie uns eine Linie zeichnen:
<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();
:
Beispiel
Lassen Sie uns ein Quadrat zeichnen:
<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();
: