Workshop › Conway's Game of Life › Step 27 of 32
Famous patterns are shared as text: one line per row, O for a live cell and . for a dead one. stamp copies such
a picture onto the grid.
```js
// Copy a text pattern onto the grid with its top left corner at (row, col).
function stamp(pattern, row, col) {
pattern.forEach((line, r) => {
for (let c = 0; c < line.length; c++) if (line[c] === 'O') grid[(row + r) % ROWS][(col + c) % COLS] = 1
})
}
```pattern.forEach((line, r) => ...) runs once for each line of text; r is the line's number.line[c] is the letter at c, line.length how many letters there are.'O' sets the cell (row + r, col + c), wrapped with % like the rest of this world.Write stamp under clear, after an empty line.
Skills: Arrays and objects, Loops
← Drag to paint The glider gun →