OwnKng

createGrid()

Creates an equally spaced grid based on a given number of columns and rows.

function createGrid(cols: number, rows: number): [number, number][] {
  return new Array(cols * rows).fill(0).map((_, i) => {
    const x = (i % cols) / cols
    const y = Math.floor(i / cols) / rows

    return [x, y]
  })
}

Notes

generative