gof-gpu
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

Game of Life GPU

Minimal library using WebGL GPGPU processing

Usage

const cells = []
let line = -1

const GameOfLifeGLInstance = new GameOfLifeGL({
    bufferSize: GRID_SIZE // size of your grid,
    initialProbability: 0.5 // probability for cells to be initially filled,
});

for (let i = 0; i < GRID_SIZE; i++) {
    const cell = document.createElement("div");
    main.appendChild(cell);

    if (i % GRID_ROW === 0) {
        line++;
    }

    cell.style.left = `${(i % GRID_ROW) * SIZE}px`;
    cell.style.top = `${line * SIZE}px`;
    cell.style.width = `${SIZE}px`;
    cell.style.height = `${SIZE}px`;

    cells.push(cell);
}

const update = () => {
    // returns array of [1, 0] 
    const grid = GameOfLifeGLInstance.update()
    cells.forEach((cell, index) => {
        cell.style.background = !!grid[index] ? "red" : "white";
    });
}

update()

See demo src/demo/index.ts

Readme

Keywords

Package Sidebar

Install

npm i gof-gpu

Weekly Downloads

2

Version

2.0.5

License

MIT

Unpacked Size

801 kB

Total Files

11

Last publish

Collaborators

  • silviopaganini