/Game-of-Life-Simulator

Optimized Conway's Game of Life Simulator with image and video recording.

Primary LanguageKotlinMIT LicenseMIT

Game of Life Simulator

Conway's Game of Life is a classic one player game/simulation. Read more about it on Wikipedia.

The simulator comes with the following features:

  • Zoomable and scrollable simulation playground
  • Optimized simulator which only simulates areas with live cells
  • Random board generation
  • Toggleable Grid Lines
  • PNG Capturing of current board state
  • Save the current board state and load it in later
  • Record the board during animation and convert to video

The App

Demo of Game of Life Simulator


Buttons/Icons Descriptions

Icon Key Description
Next Icon RIGHT ARROW Moves the simulation to the next generation.
Reset Icon BACKSPACE Clears the simulation board.
Random Icon D Randomly fills the simulation board.
Save Icon S Saves the current state of the board as a .golf file.
Snapshot Icon C Saves the current state of the board as a .png file in the Snapshots directory which is automatically generated on startup.
Recording Icon R Toggles Recording Mode. If recording mode is on, any changes made to the board by clicking NEXT are recorded.
Search Files Icon F Opens all .golf files and allows the user to load in a new simulation state.
Zoom In Files Icon = Zooms in on the simulation board.
Zoom Out Files Icon - Zooms out on the simulation board.
Grid Lines Files Icon G Toggles simulation board grid lines.

golf File Format and Loading Files

When the user presses the Save button, the current state of the board will be saved in a golf (Game Of Life File) file with the following format:

SIZE
index1
index2
index3
...

where SIZE is the size of the board (the board is always a SIZE by SIZE square) and index1, index2, index3, ... represent the indices where cells are alive. The indices are flattened. Given an x coordinate and a y coordinate on a board with size size, the formula to calculate the coordinate is coordinate = x * size + y. If you'd like to create your own designs and load them into the simulator, simply create a file in the format above, where you specify the size of your square board and the coordinates of every square you'd like to be alive.

These files are saved in the Saved directory which is automatically generated on startup.

golfr File Format

The .golfr file format is the s file format used to store multiple frames of simulation. The file format is the same as the .golf format, without the SIZE parameter at the front. The SIZE is specified on the first line of this file. It simply stores the coordinates of each cell as a comma separated list on every line in the file.

These files are saved in the Recordings directory which is automatically generated on startup.

Recording and convert.py

Once the user presses the Record button, a file called Recording{X}.golfr (X is a number) is created. This file will contain the state of the board for every frame that was recorded. To convert this file to a video format, use convert.py.

convert.py usage:

cd Recordings
python convert.py -f FILENAME -t TYPE -r RESOLUTION -fps FPS
usage: convert.py [-h] [-f FILENAME] [-t TYPE] [-r RESOLUTION] [-fps FPS]

Convert recorded .golfr files into video.

optional arguments:
  -h, --help                                show this help message and exit
  -f FILENAME, --filename FILENAME          The filename of the .golf file to convert.
  -t TYPE, --filetype TYPE                  The file type of video to convert to.
  -r RESOLUTION, --resolution RESOLUTION    The size of the cells in the video.
  -fps FPS, --fps FPS                       The frames per second of the video.

convert.py dependencies:

  • Python 3.7+
  • numpy
  • imageio
  • tqdm

Note that convert.py is just one way of converting the data into video form. Modify the script to customize the video you get out of it.

Gallery

Example Snapshot


Recording GIF