{"id":15649187,"url":"https://github.com/robertmartin8/pygameoflife","last_synced_at":"2026-03-05T18:38:46.489Z","repository":{"id":109649815,"uuid":"95112199","full_name":"robertmartin8/PyGameofLife","owner":"robertmartin8","description":"Conway's Game of Life using python's matplotlib and numpy","archived":false,"fork":false,"pushed_at":"2019-11-20T22:28:38.000Z","size":3532,"stargazers_count":46,"open_issues_count":1,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-25T09:01:52.698Z","etag":null,"topics":["animation","cellular-automata","educational","game-of-life","gif","matplotlib-animation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertmartin8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-22T12:15:53.000Z","updated_at":"2025-02-12T05:51:57.000Z","dependencies_parsed_at":"2023-07-24T05:31:13.783Z","dependency_job_id":null,"html_url":"https://github.com/robertmartin8/PyGameofLife","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertmartin8%2FPyGameofLife","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertmartin8%2FPyGameofLife/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertmartin8%2FPyGameofLife/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertmartin8%2FPyGameofLife/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertmartin8","download_url":"https://codeload.github.com/robertmartin8/PyGameofLife/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242667466,"owners_count":20166296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","cellular-automata","educational","game-of-life","gif","matplotlib-animation"],"created_at":"2024-10-03T12:28:41.030Z","updated_at":"2026-03-05T18:38:41.462Z","avatar_url":"https://github.com/robertmartin8.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg width=30% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/logo.gif\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e PyGameofLife \u003c/h1\u003e\n\n\u003c!-- buttons --\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.python.org/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/python-v3-blue.svg?style=for-the-badge\"\n            alt=\"python\"\u003e\u003c/a\u003e \u0026nbsp;\n    \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge\"\n            alt=\"MIT license\"\u003e\u003c/a\u003e \u0026nbsp;\n    \u003ca href=\"https://github.com/robertmartin8/PyPortfolioOpt/graphs/commit-activity\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Maintained%3F-yes-blue.svg?style=for-the-badge\"\n            alt=\"maintained\"\u003e\u003c/a\u003e \u0026nbsp;\n\u003c/p\u003e\n\nPyGameofLife is a simple implementation of Conway’s Game of Life in python, with a command-line interface that can generate pretty gifs. The source code emphasises simplicity and intuitive code rather than efficiency. A quick demo is shown here:\n\n```bash\npython life.py -seed r_pentomino -n 500 -interval 50\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=50% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/r_pentomino.gif\"\u003e\n\u003c/p\u003e\n\n# Contents\n\n- [Getting started](#getting-started)\n- [User guide](#user-guide)\n  - [The seed](#the-seed)\n  - [Size and position](#size-and-position)\n  - [Colours](#colours)\n  - [Animation paramaters](#animation-paramaters)\n- [About](#about)\n\n## Getting started\n\nBecause this is just a small educational script, I have chosen not to distribute it on PyPI. The only dependencies are `numpy` and `matplotlib`, which can be installed easily via `pip`:\n\n```bash\npip install numpy matplotlib\n```\n\nTo get started with PyGameofLife, navigate to a directory where you want to use the project, then clone it with:\n\n```bash\ngit clone https://github.com/robertmartin8/PyGameofLife\n```\n\nMove into the directory that was just created (either through your filesystem or with `cd PyGameofLife`), and you are ready to go!\n\nIf you don't want to use `git clone` for whatever reason, you can manually download it, unzip it, and move the folder somewhere convenient (preferably either the desktop or your home directory). Then, open up your command line, and `cd` to the correct directory. For example:\n\n```bash\ncd Users/your_username/Desktop/PyGameofLife-master\n```\n\nThat's all. You can interface with PyGameofLife via the command line. As an example, try running the following:\n\n```bash\npython life.py\n```\n\nAfter a brief moment, you should see `infinite.gif` appear. Open the file with any gif viewer (your  browser should work):\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=50% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/infinite.gif\"\u003e\n\u003c/p\u003e\n\nThere are many many things you can customise.\n\n## User guide\n\nIf at any time you need a quick reference, just run the `help` command:\n\n```bash\npython life.py --help\n```\n\nWhich will give you the following\n\n```bash\nusage: life.py [-h] [--universe-size UNIVERSE_SIZE] [-seed SEED] [-n N]\n               [-quality QUALITY] [-cmap CMAP] [-interval INTERVAL]\n               [--seed-position SEED_POSITION]\n\nPyGameofLife. By default, produces 50 generations of the 'infinite' seed\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --universe-size UNIVERSE_SIZE\n                        comma-separated dimensions of universe (x by y)\n  -seed SEED            seed for Life, see readme for list\n  -n N                  number of universe iterations\n  -quality QUALITY      image quality in DPI\n  -cmap CMAP            colour scheme\n  -interval INTERVAL    interval (in milliseconds) between iterations\n  --seed-position SEED_POSITION\n                        comma-separated coordinates of seed\n```\n\nHowever, I wll present some of the different options along with animations below.\n\n### The seed\n\nThis is arguably where all of the magic of Life lies: simple seeds can produce exceedingly complex behaviour (it can be used to build a [Turing machine](http://rendell-attic.org/gol/tm.htm)), which is near-impossible to predict just by looking at the seed.\n\nA seed is just a starting pattern that is placed somewhere in the universe. There are a number of seeds built in, and they should be referred to by the names below.\n\n```bash\n{\n    \"diehard\": [[0, 0, 0, 0, 0, 0, 1, 0],\n                [1, 1, 0, 0, 0, 0, 0, 0],\n                [0, 1, 0, 0, 0, 1, 1, 1]],\n\n    \"boat\": [[1, 1, 0],\n            [1, 0, 1],\n            [0, 1, 0]],\n\n    \"r_pentomino\": [[0, 1, 1],\n                    [1, 1, 0],\n                    [0, 1, 0]],\n\n    \"pentadecathlon\": [[1, 1, 1, 1, 1, 1, 1, 1],\n                    [1, 0, 1, 1, 1, 1, 0, 1],\n                    [1, 1, 1, 1, 1, 1, 1, 1]],\n\n    \"beacon\": [[1, 1, 0, 0],\n            [1, 1, 0, 0],\n            [0, 0, 1, 1],\n            [0, 0, 1, 1]],\n\n    \"acorn\": [[0, 1, 0, 0, 0, 0, 0],\n            [0, 0, 0, 1, 0, 0, 0],\n            [1, 1, 0, 0, 1, 1, 1]],\n\n    \"spaceship\": [[0, 0, 1, 1, 0],\n                [1, 1, 0, 1, 1],\n                [1, 1, 1, 1, 0],\n                [0, 1, 1, 0, 0]],\n\n    \"block_switch_engine\": [[0, 0, 0, 0, 0, 0, 1, 0],\n                            [0, 0, 0, 0, 1, 0, 1, 1],\n                            [0, 0, 0, 0, 1, 0, 1, 0],\n                            [0, 0, 0, 0, 1, 0, 0, 0],\n                            [0, 0, 1, 0, 0, 0, 0, 0],\n                            [1, 0, 1, 0, 0, 0, 0, 0]],\n\n    \"infinite\": [[1, 1, 1, 0, 1],\n                [1, 0, 0, 0, 0],\n                [0, 0, 0, 1, 1],\n                [0, 1, 1, 0, 1],\n                [1, 0, 1, 0, 1]],\n}\n```\n\nSo you can do something like:\n\n```bash\npython life.py -seed diehard\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=50% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/infinite.gif\"\u003e\n\u003c/p\u003e\n\nIf you'd like to add your own seed, the best way is to edit the source code and add it to the `seeds` dictionary at the top of `life.py`. By the way, if you try `boat` and it doesn't seem to be working, there's a [good reason](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life).\n\nIf you'd like to change the starting position of the seed, you can specify the coordinates (comma separated `x` and `y`) where the top-left of the seed will be placed.\n\n```bash\npython life.py -seed diehard --seed-position 20,20\n```\n\n### Size and position\n\nBy default, the size of the universe is 100x100. This is quite big relative to the size of most of the seeds, but is useful because many seeds in Life produce quite expansive results. But say you want a nice picture of the beacon, which we know is roughly the shape of a 4x4 square. We therefore probably want a 6x6 universe, with the top-left of the seed pegged at coordinates (1,1), because indexing starts from 0 in python.\n\n```bash\npython life.py -seed beacon --universe-size 6,6  --seed-position 1,1\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=50% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/beacon.gif\"\u003e\n\u003c/p\u003e\n\nAs seen above, if you want to change the size of size of the grid, you **must** also specify the coordinates of the seed, otherwise you will probably get a nasty error.\n\n### Colours\n\nColours are amended with the `-cmap` flag. A list of all possible colourmaps can be found in the\n[matplotlib documentation](https://matplotlib.org/examples/color/colormaps_reference.html). Note,\nhowever, that you will only get the colours at each end of the spectrum, because the cells in\nLife are either dead (0) or alive (1). Colourmaps can be reversed by appending `_r` to the name of the original colourmap. Please note that the cmap names are case sensitive.\n\n```bash\npython life.py -seed beacon -cmap plasma_r --universe-size 6,6  --seed-position 1,1\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=50% src=\"https://github.com/robertmartin8/PyGameofLife/blob/master/media/beacon_plasma.gif\"\u003e\n\u003c/p\u003e\n\n### Animation paramaters\n\n- The `-n` flag controls the number of iterations: the time taken to produce the animation grows linearly with the number of iterations.\n- `-interval` is quite useful, and changes the rate at which Life iterates. In the simple example of the beacon, you could increase the flashing frequency by reducing the interval.\n- Lastly, `-quality` dictates the image quality of the resulting animation. Be warned that higher DPI values greatly increase both the time taken to generate animations and the resulting fileszie.\n\n## About\n\nThis is just a quick project to demonstrate the versatility of matplotlib's animation functions. PyGameofLife definitely doesn't present the most efficient solution, but the code is readable and intuitive (and arguably produces pretty output).\n\nFor a write-up explaining a little bit more about how the code works, check out the related [article](https://reasonabledeviations.com/2017/06/10/conway-python/) on my website.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertmartin8%2Fpygameoflife","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertmartin8%2Fpygameoflife","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertmartin8%2Fpygameoflife/lists"}