UNPKG

@thi.ng/rasterize

Version:

Headless 2D shape drawing, filling & rasterization for arbitrary targets/purposes (no canvas required)

16 lines (15 loc) 398 B
import { ensureShader2D } from "./checks.js"; import { drawLine } from "./line.js"; const drawPolyLine = (grid, pts, val, closed = false) => { val = ensureShader2D(val); const n = pts.length; let [i, j] = closed ? [0, n - 1] : [1, 0]; for (; i < n; j = i, i++) { const a = pts[j]; const b = pts[i]; drawLine(grid, a[0], a[1], b[0], b[1], val); } }; export { drawPolyLine };