vertices

View sourcevertices(ctx: CanvasRenderingContext2D | Path2D, vertices: ArrayLike<number>, close?: boolean): void

Builds a path from flat coordinate pairs on a Canvas 2D drawing target.

The target may be a CanvasRenderingContext2D or Path2D. Values are consumed as [x, y] pairs: the first pair is passed to moveTo, and each later pair is passed to lineTo. Fewer than two values return without changing the target. When close is true, the default, the helper adds a final line segment back to the first pair; passing false leaves the path open.

Examples

import { vertices } from '@wimaengine/render-canvas2d'

const path = new Path2D()
vertices(path, [0, 0, 10, 0, 10, 10])

Parameters

NameDescriptionDefault
ctx

Canvas 2D context or path to update.

—
vertices

Numeric values in flat [x, y] pair order.

—
close?

Whether to add a segment back to the first pair.

true

Returns

Always returns undefined.