UNPKG

@thi.ng/grid-iterators

Version:

2D grid and shape iterators w/ multiple orderings

15 lines (14 loc) 314 B
import { __opts } from "./utils.js"; function* zigzagColumns2d(opts) { const { cols, rows, tx } = __opts(opts); const num = cols * rows; for (let i = 0; i < num; i++) { const x = i / rows | 0; let y = i % rows; x & 1 && (y = rows - 1 - y); yield tx(x, y); } } export { zigzagColumns2d };