Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,14 @@ const drawCells = () => {
const cells = new Uint8Array(memory.buffer, cellsPtr, width * height);

ctx.beginPath();

// Alive cells.
ctx.fillStyle = ALIVE_COLOR;
for (let row = 0; row < height; row++) {
for (let col = 0; col < width; col++) {
const idx = getIndex(row, col);
if (cells[idx] !== Cell.Alive) {
continue;
}

ctx.fillRect(
col * (CELL_SIZE + 1) + 1,
row * (CELL_SIZE + 1) + 1,
CELL_SIZE,
CELL_SIZE
);
}
}

// Dead cells.
ctx.fillStyle = DEAD_COLOR;

for (let row = 0; row < height; row++) {
for (let col = 0; col < width; col++) {
const idx = getIndex(row, col);
if (cells[idx] !== Cell.Dead) {
continue;
if (cells[idx] === Cell.Alive) {
ctx.fillStyle = ALIVE_COLOR;
} else if(cells[idx] === Cell.Dead) {
ctx.fillStyle = DEAD_COLOR;
}

ctx.fillRect(
Expand Down Expand Up @@ -183,9 +165,9 @@ canvas.addEventListener("click", event => {
const col = Math.min(Math.floor(canvasLeft / (CELL_SIZE + 1)), width - 1);

universe.toggle_cell(row, col);

drawCells();

drawGrid();
drawCells();
});

play();