# grid_engine
## Description
**grid_engine** is a framework for generating and manipulating grids. It provides a number of classes and functions for generating and manipulating grids. Each grid is composed of [Cell](#Cell) objects and is defined by a [Blueprint](#Blueprint). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It can be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.
## Installation
To install **grid_engine**, run the following command:
```bash
pip install gridengine_framework
```
## Usage
To use **gridengine** you can import any number of the submodules and utilize its respective features or you can import the main module.
```python
import grid_engine as ge
# Create a grid
grid = ge.grid.Grid(cell_size=10, grid_dimensions=(1000, 1000))
# Save a grid
ge.grid.save_grid(grid)
# Load a grid
loaded_grid = ge.grid.Grid.load_grid(1)
```
**grid_engine** also provides a command line interface. To use it, run the following command:
```bash
python -m grid_engine --help
# Output:
# usage: gridengine [-h] [-i] [-b BLUEPRINT] [--ascii] [-l LOAD] [-t] [-ns NOISE_SCALE] [-no NOISE_OCTAVES] [-nr NOISE_ROUGHNESS] [-r ROWS] [-c COLUMNS] [-s SIZE] [-S] [-T TYPE] [-v]
# Generate a visualized grid from a blueprint. For producing a blueprint, see the blueprint module.
# options:
# -h, --help show this help message and exit
# -i, --interactive Run an interactive session
# -b BLUEPRINT, --blueprint BLUEPRINT
# Load a blueprint from a file
# --ascii Print the grid as ascii
# -l LOAD, --load LOAD Load a grid from a file
# -t, --terrain Whether to generate terrain with the grid.
# -ns NOISE_SCALE, --noise-scale NOISE_SCALE
# Noise scale
# -no NOISE_OCTAVES, --noise-octaves NOISE_OCTAVES
# Noise octaves
# -nr NOISE_ROUGHNESS, --noise-roughness NOISE_ROUGHNESS
# Noise roughness
# -r ROWS, --rows ROWS Number of rows in the grid
# -c COLUMNS, --columns COLUMNS
# Number of columns in the grid
# -s SIZE, --size SIZE Size of each cell in the grid
# -S, --save Save the grid object to a file
# -T TYPE, --type TYPE Type of file to save the grid as
# -v, --verbose Verbose output
```
## Examples
The following examples demonstrate the use of the **grid_engine** package.
### CLI
The following command:
```bash
python -m grid_engine -v -S -t -ns 400 -no 75 -nr 0.55 -r 450 -c 800 -s 2
```
Will produce the following output:
```bash
Generating blueprint with cell size 2, 450 rows and 800 columns. Total_cells: 360000 ...
Success! Blueprint generated. Dimensions: (1600, 900)
Building grid from blueprint ...
Finding landmasses ...
Separating islands from landmasses ...
done
Finding start to river ...
Found largest landmass: 0 with 302951 cells
Finding lake coastal cells ...
Found 1094 cells.
Validating start/end of river ...
Start cell: pd00229(445, 228), End cell: dq00087(146, 86))
Building river ...
Getting river cells by walk ...
Generating river with end designated ...
Cells in river: 300 | Current cell: kb00082 | Next cell: kc00082
River steps: 300
Found largest landmass: 0 with 302951 cells
Finding lake coastal cells ...
Found 1094 cells.
Validating start/end of river ...
Start cell: ip00499(275, 498), End cell: dv00087(151, 86)
Building river ...
Getting river cells by walk ...
Generating river with end designated ...
Cells in river: 757 | Current cell: dz00082 | Next cell: ea000814
River steps: 757
done
Success! Grid generated.
Pickling grid ...
Success!
Pickling blueprint ...
Success!
Generating grid image ...
Importing pillow ...
Preparing raw image ...
Counting cells ...
Total cells: 360000
Shuffling cells ...
Cells drawn. 100%
Saving grid image ...
Grid ID: 8d564
```
The following image is the result of the above command:
![grid](saves/cf1b9/grid.png)
*The river generation algorithm is not perfect. I am currently working on improving it.*
The above command will also produce the following files(Not included in the repository... That is, generate your own!):
* `grid.cf1b9.pickle`: A pickled Grid object.
* `blueprint.cf1b9.pickle`: A pickled TerrainGridBlueprint object.
```python
import grid_engine
from grid_engine import Grid
# Load the 8d564 grid(assuming you've not generated any other grids)
_8d564 = Grid.load_grid('8d564')
print(_8d564.grid_id)
# output: 'fb16965aa77f44138dd6149b823ee9e4'
# Get a random cell
cellA = _8d564.random_cell(attr=('passable', True))
# Get another
cellB = _8d564.random_cell(attr=('passable', True))
# Get a path from cellA to cellB
path, cost = _8d564.get_path(cellA, cellB)
print(path)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/primal-coder/grid-engine",
"name": "gridengine-framework",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "game development 2d grid world generation procedural generation cell numpy pillow pyglet pymunk cli",
"author": "James Evans",
"author_email": "joesaysahoy@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/9b/86/8d8f23d0f485407df312e314c02acfb7b812ba7196799dca654e70b90919/gridengine_framework-0.91.9.tar.gz",
"platform": null,
"description": "# grid_engine\n\n## Description\n\n**grid_engine** is a framework for generating and manipulating grids. It provides a number of classes and functions for generating and manipulating grids. Each grid is composed of [Cell](#Cell) objects and is defined by a [Blueprint](#Blueprint). A grid can be generated from a blueprint, loaded from a file, or created manually. It can also be pickled for later use. It can be rendered as a 2D image, an animated GIF or an ASCII string. Grids provide a number of relevant methods for pathfinding, cell manipulation, and more.\n\n## Installation\n\nTo install **grid_engine**, run the following command:\n\n ```bash\n pip install gridengine_framework\n ```\n\n## Usage\n\nTo use **gridengine** you can import any number of the submodules and utilize its respective features or you can import the main module.\n\n ```python\n import grid_engine as ge\n \n # Create a grid\n grid = ge.grid.Grid(cell_size=10, grid_dimensions=(1000, 1000))\n \n # Save a grid\n ge.grid.save_grid(grid)\n \n # Load a grid\n loaded_grid = ge.grid.Grid.load_grid(1)\n ```\n\n**grid_engine** also provides a command line interface. To use it, run the following command:\n\n ```bash\n python -m grid_engine --help\n\n # Output:\n # usage: gridengine [-h] [-i] [-b BLUEPRINT] [--ascii] [-l LOAD] [-t] [-ns NOISE_SCALE] [-no NOISE_OCTAVES] [-nr NOISE_ROUGHNESS] [-r ROWS] [-c COLUMNS] [-s SIZE] [-S] [-T TYPE] [-v]\n\n # Generate a visualized grid from a blueprint. For producing a blueprint, see the blueprint module.\n\n # options:\n # -h, --help show this help message and exit\n # -i, --interactive Run an interactive session\n # -b BLUEPRINT, --blueprint BLUEPRINT\n # Load a blueprint from a file\n # --ascii Print the grid as ascii\n # -l LOAD, --load LOAD Load a grid from a file\n # -t, --terrain Whether to generate terrain with the grid.\n # -ns NOISE_SCALE, --noise-scale NOISE_SCALE\n # Noise scale\n # -no NOISE_OCTAVES, --noise-octaves NOISE_OCTAVES\n # Noise octaves\n # -nr NOISE_ROUGHNESS, --noise-roughness NOISE_ROUGHNESS\n # Noise roughness\n # -r ROWS, --rows ROWS Number of rows in the grid\n # -c COLUMNS, --columns COLUMNS\n # Number of columns in the grid\n # -s SIZE, --size SIZE Size of each cell in the grid\n # -S, --save Save the grid object to a file\n # -T TYPE, --type TYPE Type of file to save the grid as\n # -v, --verbose Verbose output\n ```\n\n## Examples\n\nThe following examples demonstrate the use of the **grid_engine** package.\n\n### CLI\n\nThe following command:\n\n ```bash\n python -m grid_engine -v -S -t -ns 400 -no 75 -nr 0.55 -r 450 -c 800 -s 2\n ```\n\nWill produce the following output:\n\n ```bash\n Generating blueprint with cell size 2, 450 rows and 800 columns. Total_cells: 360000 ...\n Success! Blueprint generated. Dimensions: (1600, 900)\n Building grid from blueprint ...\n Finding landmasses ...\n Separating islands from landmasses ...\n done\n Finding start to river ...\n Found largest landmass: 0 with 302951 cells\n Finding lake coastal cells ...\n Found 1094 cells.\n Validating start/end of river ...\n Start cell: pd00229(445, 228), End cell: dq00087(146, 86))\n Building river ...\n Getting river cells by walk ...\n Generating river with end designated ...\n Cells in river: 300 | Current cell: kb00082 | Next cell: kc00082\n River steps: 300\n Found largest landmass: 0 with 302951 cells\n Finding lake coastal cells ...\n Found 1094 cells.\n Validating start/end of river ...\n Start cell: ip00499(275, 498), End cell: dv00087(151, 86)\n Building river ...\n Getting river cells by walk ...\n Generating river with end designated ...\n Cells in river: 757 | Current cell: dz00082 | Next cell: ea000814\n River steps: 757\n done\n Success! Grid generated.\n Pickling grid ...\n Success!\n Pickling blueprint ...\n Success!\n Generating grid image ...\n Importing pillow ...\n Preparing raw image ...\n Counting cells ...\n Total cells: 360000\n Shuffling cells ...\n Cells drawn. 100%\n Saving grid image ...\n Grid ID: 8d564\n ```\n\nThe following image is the result of the above command:\n\n![grid](saves/cf1b9/grid.png)\n\n*The river generation algorithm is not perfect. I am currently working on improving it.*\n\nThe above command will also produce the following files(Not included in the repository... That is, generate your own!):\n\n* `grid.cf1b9.pickle`: A pickled Grid object.\n* `blueprint.cf1b9.pickle`: A pickled TerrainGridBlueprint object.\n\n ```python\n import grid_engine\n from grid_engine import Grid\n\n # Load the 8d564 grid(assuming you've not generated any other grids)\n _8d564 = Grid.load_grid('8d564')\n\n print(_8d564.grid_id)\n # output: 'fb16965aa77f44138dd6149b823ee9e4'\n\n # Get a random cell\n cellA = _8d564.random_cell(attr=('passable', True))\n\n # Get another\n cellB = _8d564.random_cell(attr=('passable', True))\n\n # Get a path from cellA to cellB\n path, cost = _8d564.get_path(cellA, cellB)\n print(path)\n ```\n",
"bugtrack_url": null,
"license": null,
"summary": "A framework for generating and manipulating grid-based game worlds",
"version": "0.91.9",
"project_urls": {
"Homepage": "https://github.com/primal-coder/grid-engine"
},
"split_keywords": [
"game",
"development",
"2d",
"grid",
"world",
"generation",
"procedural",
"generation",
"cell",
"numpy",
"pillow",
"pyglet",
"pymunk",
"cli"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9b868d8f23d0f485407df312e314c02acfb7b812ba7196799dca654e70b90919",
"md5": "cd72b4b22e990512524cc80775bb81da",
"sha256": "e4c6ca614ab51e86748bd48015bbbae1bfa8a773b43c3fcc18f8598bc1ac168a"
},
"downloads": -1,
"filename": "gridengine_framework-0.91.9.tar.gz",
"has_sig": false,
"md5_digest": "cd72b4b22e990512524cc80775bb81da",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 51049,
"upload_time": "2024-09-01T07:45:42",
"upload_time_iso_8601": "2024-09-01T07:45:42.138553Z",
"url": "https://files.pythonhosted.org/packages/9b/86/8d8f23d0f485407df312e314c02acfb7b812ba7196799dca654e70b90919/gridengine_framework-0.91.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-01 07:45:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "primal-coder",
"github_project": "grid-engine",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "gridengine-framework"
}