Skip to content

Instantly share code, notes, and snippets.

@computercam
Created June 19, 2022 14:05
Show Gist options
  • Select an option

  • Save computercam/75401a526bd369e9697ac3966077ac26 to your computer and use it in GitHub Desktop.

Select an option

Save computercam/75401a526bd369e9697ac3966077ac26 to your computer and use it in GitHub Desktop.

Revisions

  1. computercam created this gist Jun 19, 2022.
    18 changes: 18 additions & 0 deletions getGrid.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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
    }