SOURCE

let gridNumber = 6
let gridArr = Array.from(new Array(Math.pow(gridNumber, 2)).keys());
let width = 100
const base = {
    x: 0,
    y: 0
}

gridArr.forEach((id) => {
    const colIdx = id % gridNumber
    const rowIdx = Math.floor(id / gridNumber)

    let leftTop = {
        x: base.x + (colIdx * width),
        y: base.y + (rowIdx * width)
    }
    let rightTop = {
        x: base.x + ((colIdx + 1) * width),
        y: base.y + ((rowIdx) * width)
    }
    let leftBottom = {
        x: base.x + (colIdx * width),
        y: base.y + ((rowIdx + 1) * width)
    }

    let rightBottom = {
        x: base.x + ((colIdx + 1) * width),
        y: base.y + ((rowIdx + 1) * width)
    }

    gridArr[id] = {
        id,
        rowIdx,
        colIdx,
        leftTop, rightTop, leftBottom, rightBottom
    }
})

console.log(gridArr)


console 命令行工具 X clear

                    
>
console