GithubHelp home page GithubHelp logo

alexeidt / game-of-life-simulator Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 0.0 32.48 MB

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

Home Page: https://youtu.be/TAyOt6cEmAI

License: MIT License

Kotlin 91.56% Python 8.44%
conways-game-of-life game-of-life-simulator cellular-automata

game-of-life-simulator's Introduction

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


game-of-life-simulator's People

Contributors

alexeidt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.