MCPcopy Create free account
hub / github.com/MultithreadedJSBook/code-samples / iterate

Method iterate

ch5-game-of-life/thread-gol.js:23–42  ·  view source on GitHub ↗
(minX, minY, maxX, maxY)

Source from the content-addressed store, hash-verified

21 ];
22
23 iterate(minX, minY, maxX, maxY) {
24 const size = this.size;
25
26 for (let x = minX; x < maxX; x++) {
27 for (let y = minY; y < maxY; y++) {
28 const cell = this.cells[size * x + y];
29 let alive = 0;
30 for (const [i, j] of Grid.NEIGHBORS) {
31 alive += this.getCell(x + i, y + j);
32 }
33 const newCell = alive === 3 || (cell && alive === 2) ? 1 : 0;
34 this.nextCells[size * x + y] = newCell;
35 this.paint(newCell, x, y);
36 }
37 }
38
39 const cells = this.nextCells;
40 this.nextCells = this.cells;
41 this.cells = cells;
42 }
43}
44
45const BLACK = 0xFF000000;

Callers 1

runWorkerFunction · 0.95

Calls 1

getCellMethod · 0.95

Tested by

no test coverage detected