Raxol.Demo.GameOfLife (Raxol v2.6.0)

View Source

Conway's Game of Life implementation for the demo showcase. Features age-based coloring where newer cells are brighter.

Summary

Functions

Creates a new grid with random initial state.

Creates an R-pentomino pattern (small but produces interesting evolution).

Returns positions of all live cells (for particle explosion).

Counts the number of live cells.

Renders the grid to ANSI escape sequences.

Advances the grid by one generation.

Types

grid()

@type grid() :: %{required({integer(), integer()}) => integer()}

Functions

create_grid(width, height, density \\ 0.3)

@spec create_grid(integer(), integer(), float()) :: grid()

Creates a new grid with random initial state.

create_r_pentomino(width, height)

@spec create_r_pentomino(integer(), integer()) :: grid()

Creates an R-pentomino pattern (small but produces interesting evolution).

live_cells(grid)

@spec live_cells(grid()) :: [{integer(), integer()}]

Returns positions of all live cells (for particle explosion).

population(grid)

@spec population(grid()) :: integer()

Counts the number of live cells.

render(grid, width, height)

@spec render(grid(), integer(), integer()) :: String.t()

Renders the grid to ANSI escape sequences.

step(grid, width, height)

@spec step(grid(), integer(), integer()) :: grid()

Advances the grid by one generation.