Skip to content

Commit

Permalink
Changed to pyproject & updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
INeido committed Jan 1, 2023
1 parent f815d60 commit 681612e
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 214 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Exports
*.csv

# VS Code
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
108 changes: 86 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,101 @@
# CGOL · [![GitHub License](https://img.shields.io/github/license/INeido/CGOL?style=for-the-badge)](https://github.com/INeido/CGOL/blob/main/LICENSE) [![PyPI](https://img.shields.io/pypi/v/CGOL?style=for-the-badge)](https://pypi.org/project/CGOL/) [![GitHub release](https://img.shields.io/github/v/release/INeido/CGOL?label=GitHub&style=for-the-badge)](https://github.com/INeido/CGOL/releases)
# CGOL · [![PyPI](https://img.shields.io/pypi/v/CGOL?style=for-the-badge&logo=PyPi)](https://pypi.org/project/CGOL/) [![GitHub release](https://img.shields.io/github/v/release/INeido/CGOL?label=GitHub&style=for-the-badge&logo=GitHub)](https://github.com/INeido/CGOL/releases) ![GitHub repo size](https://img.shields.io/github/repo-size/INeido/CGOL?style=for-the-badge) ![GitHub License](https://img.shields.io/github/license/INeido/CGOL?style=for-the-badge)

A Conway's Game of Life implementation using numpy and pygame.

A whack Conway's Game of Life implementation.

![](https://github.com/INeido/CGOL/blob/main/img/demo0.png?raw=true)
![](https://github.com/INeido/CGOL/blob/main/samples/logo.png?raw=true)

## Description

Play around with cellular automata.
This project has no particular aim. It is a purely a personal project and barely maintained.

It is a CLI based [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life): implementation using numpy for fast calculations and pygame for an interactive simulation.

---

Rules of Conway's Game of Life
1. Any live cell with two or three live neighbors survives.
2. Any dead cell with three live neighbors becomes a live cell.
3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.

## Installing

Install using pip
```bash
pip install cgol
```

Manually install using CLI
```bash
git clone https://github.com/INeido/CGOL
pip install -e CGOL/.
```

## Usage

![](https://github.com/INeido/CGOL/blob/main/img/demo1.png?raw=true)
Here are some examples.

Start a simulation with the default setting but with a custom seed.
```bash
cgol -s 42
```
![](https://github.com/INeido/CGOL/blob/main/samples/demo1.gif?raw=true)

Change grid size, cell size and fade color.
```bash
cgol -cf 130 20 0 -cs 8 -sx 90 -sy 160
```
![](https://github.com/INeido/CGOL/blob/main/samples/demo2.gif?raw=true)

Change the color to white on black without fade.
```bash
cgol -fd 0.0 -ca 255 255 255
```
![](https://github.com/INeido/CGOL/blob/main/samples/demo3.gif?raw=true)

Draw with the mouse to birth or kill cells.

![](https://github.com/INeido/CGOL/blob/main/img/demo0.gif?raw=true)
![](https://github.com/INeido/CGOL/blob/main/samples/demo0.gif?raw=true)


## Arguments

```
usage: CGOL [-h] [--res-h RH] [--res-w RW] [--colour-alive CA [CA ...]] [--colour-dead CD [CD ...]] [--colour-fade CF [CF ...]]
[--colour-background CB [CB ...]] [--cell_size CS] [--size-x SX] [--size-y SY] [--tickrate T] [--seed S] [--save-file F] [--load L]
[--pause-stalemate PS] [--pause-oscillators PO] [--fade-rate FR] [--fade-death-value FD]
Conway's Game of Life
options:
-h, --help show this help message and exit
--res-h RH, -rh RH Height of the Game.
--res-w RW, -rw RW Width of the Game.
--colour-alive CA [CA ...], -ca CA [CA ...]
Colour for alive cells. 'R G B'
--colour-dead CD [CD ...], -cd CD [CD ...]
Colour for dead cells. 'R G B'
--colour-fade CF [CF ...], -cf CF [CF ...]
Colour to fade dead cells to. 'R G B'
--colour-background CB [CB ...], -cb CB [CB ...]
Colour for dead cells. 'R G B'
--cell_size CS, -cs CS
Size of a cell in pixel.
--size-x SX, -sx SX Height of the World.
--size-y SY, -sy SY Width of the World.
--tickrate T, -t T Number of times the game shall update in a second (FPS).
--seed S, -s S Seed value used to create World.
--save-file F, -f F Path of the in-/output file. (Should be .csv)
--load L, -l L Load revious save.
--pause-stalemate PS, -ps PS
Game pauses on a stalemate.
--pause-oscillators PO, -po PO
Game pauses when only oscillators remain.
--fade-rate FR, -fr FR
Value by which a cell should decrease every generation.
--fade-death-value FD, -fd FD
Value a cell should have after death.
```

| Argument | Description | Default Value |
| ------ | ------ | ------ |
| --res-h (-rh) | Height of the Game. | 720 |
Expand Down Expand Up @@ -60,18 +139,3 @@ Draw with the mouse to birth or kill cells.
| Right Arrow | Forward one generation. |
| + | Extend grid by one cell in every direction. |
| - | Reduce grid by one cell in every direction. |

## Installing

You can install the code and download the requirements with the following commands.
```bash
git clone https://github.com/INeido/CGOL
cd CGOL
pip install -r requirements.txt
python ./src/cgol/__main__.py
```

Alternatively, install using pip
```bash
pip install cgol
```
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "CGOL"
version = "0.8.0"
description = "A whack Conway's Game of Life implementation."
readme = "README.md"
requires-python = ">=3"
license = {text = "GPL-3"}
classifiers = [
"Programming Language :: Python :: 3",
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Games/Entertainment :: Simulation",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
"Natural Language :: English",
]
authors = [
{name = "Neido", email = "[email protected]"}
]
maintainers = [
{name = "Neido", email = "[email protected]"}
]
dependencies = [
"pygame",
"numpy",
]

[project.urls]
Homepage = "https://github.com/INeido/CGOL/"
Repository = "https://github.com/INeido/CGOL/"
Issues = "https://github.com/INeido/CGOL/issues"

[project.scripts]
cgol = "cgol.__main__:main"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
argparse
pygame
numpy
-e .
File renamed without changes
File renamed without changes
Binary file added samples/demo1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/demo2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/demo3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
42 changes: 0 additions & 42 deletions setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

40 changes: 40 additions & 0 deletions src/cgol/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from .game import Game
import argparse


def main():
# Gather arguments
parser = argparse.ArgumentParser(prog="CGOL", description="Conway's Game of Life")
parser.add_argument("--res-h", "-rh", dest="rh", default=720, type=int, required=False, help="Height of the Game.")
parser.add_argument("--res-w", "-rw", dest="rw", default=1280, type=int, required=False, help="Width of the Game.")
parser.add_argument("--color-alive", "-ca", dest="ca", default=(255, 144, 0), type=int, required=False, help="Colour for alive cells. 'R G B'", nargs='+')
parser.add_argument("--color-dead", "-cd", dest="cd", default=(0, 0, 0), type=int, required=False, help="Colour for dead cells. 'R G B'", nargs='+')
parser.add_argument("--color-fade", "-cf", dest="cf", default=(0, 0, 0), type=int, required=False, help="Colour to fade dead cells to. 'R G B'", nargs='+')
parser.add_argument("--color-background", "-cb", dest="cb", default=(16, 16, 16), type=int, required=False, help="Colour for dead cells. 'R G B'", nargs='+')
parser.add_argument("--cell_size", "-cs", dest="cs", default=16, type=int, required=False, help="Size of a cell in pixel.")
parser.add_argument("--size-x", "-sx", dest="sx", default=45, type=int, required=False, help="Height of the World.")
parser.add_argument("--size-y", "-sy", dest="sy", default=80, type=int, required=False, help="Width of the World.")
parser.add_argument("--tickrate", "-t", dest="t", default=30, type=float, required=False, help="Number of times the game shall update in a second (FPS).")
parser.add_argument("--seed", "-s", dest="s", default=-1, type=int, required=False, help="Seed value used to create World.")
parser.add_argument("--save-file", "-f", dest="f", default="./cgol.csv", type=str, required=False, help="Path of the in-/output file. (Should be .csv)")
parser.add_argument("--load", "-l", dest="l", default=False, type=bool, required=False, help="Load revious save.")
parser.add_argument("--pause-stalemate", "-ps", dest="ps", default=False, type=bool, required=False, help="Game pauses on a stalemate.")
parser.add_argument("--pause-oscillators", "-po", dest="po", default=False, type=bool, required=False, help="Game pauses when only oscillators remain.")
parser.add_argument("--fade-rate", "-fr", dest="fr", default=0.01, type=float, required=False, help="Value by which a cell should decrease every generation.")
parser.add_argument("--fade-death-value", "-fd", dest="fd", default=0.5, type=float, required=False, help="Value a cell should have after death.")
args = parser.parse_args()

# Create new Game
game = Game(args.rh, args.rw, tuple(args.ca), tuple(args.cd), tuple(args.cf), tuple(args.cb), args.cs, args.t, args.f, args.ps, args.po)

game.setup_pygame()

# Let Game create the World
game.create_world(args.sx, args.sy, args.s, args.l, args.fr, args.fd)

# Start Game
game.game_loop()


if __name__ == "__main__":
main()
50 changes: 1 addition & 49 deletions src/cgol/__main__.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,4 @@
"""
CGOL
====
A whack Conway's Game of Life implementation.
Rules of Conway's Game of Life:
1. Any live cell with two or three live neighbours survives.
2. Any dead cell with three live neighbours becomes a live cell.
3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.
Github Repo:
https://github.com/INeido/CGOL
"""
from game import Game
import argparse


def main():
# Gather arguments
parser = argparse.ArgumentParser(prog="CGOL", description="Conway's Game of Life")
parser.add_argument("--res-h", "-rh", dest="rh", default=720, type=int, required=False, help="Height of the Game.")
parser.add_argument("--res-w", "-rw", dest="rw", default=1280, type=int, required=False, help="Width of the Game.")
parser.add_argument("--colour-alive", "-ca", dest="ca", default=(255, 144, 0), type=int, required=False, help="Colour for alive cells. 'R G B'", nargs='+')
parser.add_argument("--colour-dead", "-cd", dest="cd", default=(0, 0, 0), type=int, required=False, help="Colour for dead cells. 'R G B'", nargs='+')
parser.add_argument("--colour-fade", "-cf", dest="cf", default=(0, 0, 0), type=int, required=False, help="Colour to fade dead cells to. 'R G B'", nargs='+')
parser.add_argument("--colour-background", "-cb", dest="cb", default=(16, 16, 16), type=int, required=False, help="Colour for dead cells. 'R G B'", nargs='+')
parser.add_argument("--cell_size", "-cs", dest="cs", default=16, type=int, required=False, help="Size of a cell in pixel.")
parser.add_argument("--size-x", "-sx", dest="sx", default=45, type=int, required=False, help="Height of the World.")
parser.add_argument("--size-y", "-sy", dest="sy", default=80, type=int, required=False, help="Width of the World.")
parser.add_argument("--tickrate", "-t", dest="t", default=30, type=float, required=False, help="Number of times the game shall update in a second (FPS).")
parser.add_argument("--seed", "-s", dest="s", default=-1, type=int, required=False, help="Seed value used to create World.")
parser.add_argument("--save-file", "-f", dest="f", default="./cgol.csv", type=str, required=False, help="Path of the in-/output file. (Should be .csv)")
parser.add_argument("--load", "-l", dest="l", default=False, type=bool, required=False, help="Load revious save.")
parser.add_argument("--pause-stalemate", "-ps", dest="ps", default=False, type=bool, required=False, help="Game pauses on a stalemate.")
parser.add_argument("--pause-oscillators", "-po", dest="po", default=False, type=bool, required=False, help="Game pauses when only oscillators remain.")
parser.add_argument("--fade-rate", "-fr", dest="fr", default=0.01, type=float, required=False, help="Value by which a cell should decrease every generation.")
parser.add_argument("--fade-death-value", "-fd", dest="fd", default=0.5, type=float, required=False, help="Value a cell should have after death.")
args = parser.parse_args()

# Create new Game
game = Game(args.rh, args.rw, tuple(args.ca), tuple(args.cd), tuple(args.cf), tuple(args.cb), args.cs, args.t, args.f, args.ps, args.po)

game.setup_pygame()

# Let Game create the World
game.create_world(args.sx, args.sy, args.s, args.l, args.fr, args.fd)

# Start Game
game.game_loop()
from . import main


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 681612e

Please sign in to comment.