Skip to content

Instantly share code, notes, and snippets.

@computercam
Created June 19, 2022 14:05
Show Gist options
  • Save computercam/75401a526bd369e9697ac3966077ac26 to your computer and use it in GitHub Desktop.
Save computercam/75401a526bd369e9697ac3966077ac26 to your computer and use it in GitHub Desktop.
generates a flat array of data for a four quadrant grid
export function getGrid (size) {
const length = Math.pow(size, 2)
const offset = (size / 2) * -1
const grid = Array.from({ length }).map((_, index, array) => {
const row = Math.floor(index / size)
const column = index % size
const x = row + offset + 0.5
const y = column + offset + 0.5
const i = index + 1
const r = array.length - index
return { x, y, i, r, row, column }
})
return grid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment