This project is part of the @thi.ng/umbrella monorepo.
Collection of 2D grid iterators, providing the following orderings:
Diagonal | Hilbert curve | Outward spiral |
---|---|---|
Zigzag columns | Zigzag rows | |
All functions have been ported from Christopher Kulla's Java-based Sunflow renderer.
For alternative 2D/3D grid iteration, also see range2d()
& range3d()
in
@thi.ng/transducers.
yarn add @thi.ng/grid-iterators
None
import * as gi from "@thi.ng/grid-iterators";
[...gi.zigzagRows2d(4, 4)]
// [
// [ 0, 0 ], [ 1, 0 ], [ 2, 0 ], [ 3, 0 ],
// [ 3, 1 ], [ 2, 1 ], [ 1, 1 ], [ 0, 1 ],
// [ 0, 2 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ],
// [ 3, 3 ], [ 2, 3 ], [ 1, 3 ], [ 0, 3 ]
// ]
- Karsten Schmidt
© 2019 Karsten Schmidt // Apache Software License 2.0