@thi.ng/grid-iterators
Version:
2D grid and shape iterators w/ multiple orderings
15 lines (14 loc) • 308 B
JavaScript
import { __opts } from "./utils.js";
function* zigzagRows2d(opts) {
const { cols, rows, tx } = __opts(opts);
const num = cols * rows;
for (let i = 0; i < num; i++) {
let x = i % cols;
const y = i / cols | 0;
y & 1 && (x = cols - 1 - x);
yield tx(x, y);
}
}
export {
zigzagRows2d
};