Created
June 19, 2022 14:05
-
-
Save computercam/75401a526bd369e9697ac3966077ac26 to your computer and use it in GitHub Desktop.
generates a flat array of data for a four quadrant grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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