UNPKG

@thi.ng/rasterize

Version:

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

19 lines (18 loc) 465 B
import { lineClipped } from "@thi.ng/grid-iterators/line"; import { __draw2D } from "./draw.js"; const drawLine = (grid, x1, y1, x2, y2, val) => __draw2D( lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]), grid, val ); const traceLine = (grid, x1, y1, x2, y2, fn) => { const pts = lineClipped(x1, y1, x2, y2, 0, 0, grid.size[0], grid.size[1]); if (pts) { for (let p of pts) fn(p); } return grid; }; export { drawLine, traceLine };