https://github.com/sondregj/conway
🧫 Cellular Automata
https://github.com/sondregj/conway
cellular-automata conway functional game-of-life typescript
Last synced: 5 months ago
JSON representation
🧫 Cellular Automata
- Host: GitHub
- URL: https://github.com/sondregj/conway
- Owner: sondregj
- License: mit
- Created: 2019-09-26T15:35:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T11:57:05.000Z (almost 3 years ago)
- Last Synced: 2025-05-12T08:33:09.241Z (5 months ago)
- Topics: cellular-automata, conway, functional, game-of-life, typescript
- Language: TypeScript
- Homepage: https://conway.sondregjellestad.space
- Size: 358 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🧫
Conway
Cellular Automata
A simple cellular automaton implementation, in TypeScript.
## Usage
Install by running `npm install @sondregj/conway`
```javascript
import { advance } from '@sondregj/conway'const world = {
cells: [
[{ alive: false }, { alive: false }, { alive: true }],
[{ alive: true }, { alive: false }, { alive: true }],
[{ alive: false }, { alive: true }, { alive: true }],
],
}const day1 = advance(world)
```You can also define custom rule functions.
```javascript
import { advance } from '@sondregj/conway'const world = {
cells: [
[{ alive: false }, { alive: false }, { alive: true }],
[{ alive: true }, { alive: false }, { alive: true }],
[{ alive: false }, { alive: true }, { alive: true }],
],
}const rules = (board, cell, x, y) => !cell.alive
const day1 = advance(world, rules)
```A convenience function for initializing boards is also included.
```javascript
import { initializeBoard, advance } from '@sondregj/conway'const genesis: Board = initializeBoard(64, 64, { random: true })
const day1 = advance(genesis)
```The following TypeScript types are included.
```typescript
import { Board, BoardTick, Cell, RuleFunction } from '@sondregj/conway'const world: Board = {
cells: [
[{ alive: false }, { alive: false }, { alive: true }],
[{ alive: true }, { alive: false }, { alive: true }],
[{ alive: false }, { alive: true }, { alive: true }],
],
}const cell: Cell = { alive: true }
const advance: BoardTick = (board: Board): Board => board
const rules: RuleFunction = (board: Board, cell: Cell, x: number, y: number): boolean =>
true
```## License
MIT © 2019 Sondre Gjellestad