Name

CanvasRenderingContext2D.closePath( ): closes an open subpath

Synopsis

void closePath( )

Description

If the current subpath of the canvas is open, closePath( ) closes it by adding a line connecting the current point to the subpath’s starting point. If the subpath is already closed, this method does nothing. Once a subpath is closed, no more lines or curves can be added to it. To continue adding to the path, you must begin a new subpath with a call to moveTo( ).

You do not need to call closePath( ) before stroking or filling a path. Paths are implicitly closed when filled (and also when you call clip( )).

See Also

CanvasRenderingContext2D.beginPath( )
CanvasRenderingContext2D.moveTo( )
CanvasRenderingContext2D.stroke( )
CanvasRenderingContext2D.fill( )

Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.