Skip to content

pcasaretto/conway-game-of-life-clj

Repository files navigation

conway-game-of-life-clj

An interactive Conway's Game of Life implementation using Clojure and Quil with support for RLE file loading, pattern centering, and real-time interaction.

Features

  • Visual simulation with animated colored cells
  • RLE file support including patterns with repeated line ends
  • Pattern centering option to center loaded patterns on the screen
  • Interactive controls:
    • Spacebar: Pause/unpause the simulation
    • Mouse click: Toggle cell liveness at clicked location
    • Mouse drag: Paint/erase cells while dragging
  • Configurable parameters: Board size, cell step size, and frame rate
  • Higher-order coloring functions for customizable cell appearance

Usage

Run the game with default settings:

clj -M:run

Run with custom options:

clj -M:run --size 100 --step 10 --fps 5

Run with an RLE file:

clj -M:run --file glider.rle

Run with a centered pattern:

clj -M:run --file gosper-gun.rle --center

Command Line Options

  • --size SIZE: Board size in number of cells (default: 50)
  • --step STEP: Cell size in pixels (default: 50)
  • --fps FPS: Frames per second (default: 1)
  • --file PATH: Load an RLE pattern file
  • --center: Center the loaded pattern on the screen

Interactive Controls

  • Spacebar: Pause or resume the simulation
  • Left click: Toggle a cell between alive and dead
  • Click and drag: Paint/erase multiple cells by dragging

RLE File Format

This implementation supports the Run Length Encoded (RLE) format commonly used for Conway's Game of Life patterns:

  • Basic patterns: bo$2bo$3o! (glider)
  • Repeated elements: 3o (3 alive cells), 5b (5 dead cells)
  • Line endings: $ (newline), 2$ (skip 2 lines)
  • Comments: Lines starting with #
  • Metadata: x = 3, y = 3, rule = B3/S23

Development

Run tests:

clj -M:test

Build an uberjar:

clj -T:build uber

Requirements

  • Java 11 or higher
  • Clojure CLI tools

About

Conway's game of life in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published