UNPKG

@thi.ng/grid-iterators

Version:

2D grid and shape iterators w/ multiple orderings

29 lines 957 B
/** * Yields iterator of 2D grid coordinates based on the recursive Diamond Square * algorithm. The given `exp` is a power of 2 exponent and the resulting * coordinates (in both directions) will be in the closed `[0,2^exp]` interval * (i.e. each axis is always a power-of-2 plus 1). * * @remarks * Reference: https://en.wikipedia.org/wiki/Diamond-square_algorithm * * @example * ```ts tangle:../export/diamond-square.ts * import { diamondSquare } from "@thi.ng/grid-iterators"; * * // generate coords for a 17x17 grid * console.log( * [...diamondSquare(4)] * ); * // [ * // [0, 0], [16, 0], [16, 16], [0, 16], [8, 0], [8, 16], * // [16, 8], [0, 8], [8, 8], [4, 0], [12, 0], [12, 16], * // [4, 16], [8, 4], [8, 12], [4, 8], [12, 8], [0, 4], * // ... * // ] * ``` * * @param exp */ export declare function diamondSquare(exp: number): Generator<number[], void, unknown>; //# sourceMappingURL=diamond-square.d.ts.map