Conway's game of life in python
Project description
Game Of Life
Simple way to play Conway's game of life in python.
You can import your own map as json file name "save.json", using get_MAP methode.
All you custom maps (in the save.json file) are available in the list custom_maps.
Other custom maps are available such as: my_map_1 and my_map_2, created using Map class :
from simple_game_of_life import Map
m = Map(100)
my_map_1 = m.mini_random_MAP((25, 20))
my_map_2 = m.kind(kind="line 10")
NOTE : Two artificials borders are created for each map,
The first one is visible while playing, it's in black.
The second one is white (invisible) just after the black border, no cell can born here
Installation
Run the following command to install:
$ pip install simple-game-of-life
Usage
for a random map
from simple_game_of_life import GameOfLife
game = GameOfLife(50) # 50 is the side (width, height) of the map
game.start_animation()
for a custom map
from simple_game_of_life import GameOfLife
from random import choice
my_custom_map = GameOfLife.get_MAP()
game = GameOfLife(custom_map=choice(my_custom_map))
game.start_animation()
# Note you can also import custom_map like that :
# from simple_game_of_life import custom_map
to implement a pattern :
from simple_game_of_life import GameOfLife, Map
glider = [[0,1,0],
[0,0,1],
[1,1,1]]
m = Map(100) # 100 is the side (width, height) of the map
my_map = m.my_pattern(glider)
game = GameOfLife(custom_map=my_map)
game.start_animation()
Other usage
GameOfLife classe :
- You can save a map by using
saved_MAPmethode. - You can get a map by using
get_MAPmethode. - You can reset all saved map by using
reset_MAPmethode. - You can get all frames by using
get_historymethode. - You can set a new animation with the same instance using
new_animationmethode.
Map classe :
full_random_MAP: all the map gonna be random.mini_random_MAP: a portion of the map gonna be random.my_pattern: insert your pattern into an empty map.kind:- insert well know pattern into an empty map, (currenly 5 patterns are available).
- random : choice randomly one of the following map
"glider""lwss": Lightweight spaceship"mwss": Middleweight spaceship"hwss": Heavyweight spaceship
- insert well know pattern into an empty map, (currenly 5 patterns are available).
You can also calculate the average time of instancing, using timeit function:
game = timeit(GameOfLife, loop=10, size_or_side=50, frames=200) # loop : number of loop
game.start_animation()
Optionals parameters
-
When instancing
GameOfLifeclasse :
Args: size_or_side ((iterable, lenght = 2) or int): either size of a matrix
or side (width, height) of a square matrix. Defaults to None.custom_map (iterable, matrix): a custom map that you created using an iterable (dim=2, matrix), or by using `Board` classe . Defaults to None. seed (int, optional): set the seed, by using `np.random.seed`. Defaults to None. frames (int, optional): number of frames calculated. Defaults to 100. zoom (float, optional): allow to create larger plot, if zoom=10 (square matrix) then the figure size will be (5, 5) inch. Defaults to 10. -
when starting the animation using
start_animation:
NOTE :
For saving : You need first to install ffmpeg : First search : Homebrew website (https://brew.sh/) Copy past the command in a Terminal, press enter. Then in a Terminal : brew install ffmpegArgs: interval_between_two_frames (int, optional): Interval between two frames in milisecond. Defaults to 100.
plot (bool, optional): Allow plotting. Defaults to True. save (bool, optional): Allow save. Defaults to False. fps (int, optional): Frames per second if saved. Defaults to 30. file_name (str, optional): file name for saved, must end by ".mp4", ".mov", ".avi", ".flv" or ".wmv", otherwise it's save with ".mp4". Defaults to None.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_game_of_life-0.1.2.tar.gz.
File metadata
- Download URL: simple_game_of_life-0.1.2.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c61644bcf05ac261ed232e982d03d4e5dd851dfbb64a5ff0e18aa1f850a9e57
|
|
| MD5 |
fa589ed7e7bc8aa4f58d5c1513a8679d
|
|
| BLAKE2b-256 |
bce908921e8f6eddd6509a27fafb28247a9ceac452c8fe488205ef7e4405de2d
|
File details
Details for the file simple_game_of_life-0.1.2-py3-none-any.whl.
File metadata
- Download URL: simple_game_of_life-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7366f06210de38aefecf297effebf0e6955e86efe5ed244ff71f0ff62542a56
|
|
| MD5 |
3aa37da3b3f104121e437a2dd1e21a51
|
|
| BLAKE2b-256 |
ea05b22c38719fa01c1a8209941f24026d4e98a019c28de275469832a08f7cbd
|