Canvas beginPath() Method
Example
Draw one green and one purple path on the canvas:
JavaScript:
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.strokeStyle = "green";
ctx.lineWidth = 5
// Begin a Path
ctx.beginPath();
ctx.moveTo(0, 75);
ctx.lineTo(250, 75);
// Draw the Path
ctx.stroke();
// Begin a new Path
ctx.beginPath();
ctx.strokeStyle = "purple";
ctx.moveTo(50, 0);
ctx.lineTo(150, 130);
// Draw the Path
ctx.stroke();
Try it Yourself »
Description
The beginPath()
method begins a path or resets the current path.
See Also:
The closePath() Method (Close current path)
The moveTo() Method (Move the path to a point)
The lineTo() Method (Add a line to the path)
The fill() Method (Fill current path)
The stroke() Method (Draw current path)
Syntax
context.beginPath() |
Parameters
NONE |
Return Value
NONE |
Browser Support
The <canvas>
element is an HTML5 standard (2014).
beginPath()
is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
❮ Canvas Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.