| 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 | |
| 45 | const BLACK = 0xFF000000; |