Try Install Learn Blog API Packages GitHub
Pages

Path2D

Functions

addPath
(
path
:
Path2D
additionalPath
:
Path2D
transform
:
DOMMatrix
)
:
Path2D

Adds a path to the current path.

arc
(
path
:
Path2D
x
:
Number
y
:
Number
radius
:
Number
startAngle
:
Number
endAngle
:
Number
counterclockwise
:
Bool
)

Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to clockwise).

arcTo
(
path
:
Path2D
x1
:
Number
y1
:
Number
x2
:
Number
y2
:
Number
radius
:
Number
)
:
Path2D

Adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.

bezierCurveTo
(
path
:
a
cp1x
:
Number
cp1y
:
Number
cp2x
:
Number
cp2y
:
Number
x
:
Number
y
:
Number
)
:
a

Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using moveTo() before creating the Bézier curve.

closePath
(
path
:
Path2D
)
:
Path2D

Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start.

If the shape has already been closed or has only one point, this function does nothing.

create
:
Path2D

Creates a new Path2D

ellipse
(
path
:
Path2D
x
:
Number
y
:
Number
radiusX
:
Number
radiusY
:
Number
rotation
:
Number
startAngle
:
Number
endAngle
:
Number
counterclockwise
:
Bool
)
:
Path2D

Adds an elliptical arc to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by counterclockwise (defaulting to clockwise).

fromPath
(
path
:
Path2D
)
:
Path2D

Create a new Path2D from an existing Path2D

fromSVGString
(
svgPath
:
String
)
:
Path2D

Create a new Path2D from an SVG Path string

lineTo
(
path
:
Path2D
x
:
Number
y
:
Number
)
:
Path2D

Connects the last point in the subpath to the (x, y) coordinates with a straight line.

moveTo
(
path
:
Path2D
x
:
Number
y
:
Number
)
:
Path2D

Moves the starting point of a new sub-path to the (x, y) coordinates.

quadraticCurveTo
(
path
:
Path2D
cpx
:
Number
cpy
:
Number
x
:
Number
y
:
Number
)
:
Path2D

Adds a quadratic Bézier curve to the current path.

rect
(
path
:
Path2D
x
:
Number
y
:
Number
width
:
number
height
:
number
)
:
Path2D

Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.

roundRect
(
path
:
Path2D
x
:
Number
y
:
Number
width
:
Number
height
:
Number
radii
:
Array(Number)
)
:
Path2D

Creates a path for a rounded rectangle at position (x, y) with a size that is determined by width and height and the radii of the circular arc to be used for the corners of the rectangle is determined by radii.