Polyhexes
Module for the Polyhexes.
- class polyhex.objects.polyhexes.Polyhex(hex_coord_system: str = 'axial', top: str = 'pointy', radius: int | float = 1, vertex_orientation: str = 'clockwise', assets: ~typing.Dict = <factory>)
Bases:
objectPolyhex Class.
From a software engineering perspective, a Polyhex is an Orchestrator. It provides convenience functions to: <br>
-> create a polyhex <br> -> display/draw a polyhex <br> -> orchestrate the recording of the graphs for later export <br>
- append_hex(hexagon: Hexagon, hypergraph: Dict)
Method to append a hexagon to a polyhex.
The Polyhex being an Orchestrator, it is its role to read the graph to record, make sure that all graphs are recorded using the right
graph.append()calls.- Parameters:
hexagon (
Hexagon) – The hexagon to append to the polyhexhypergraph (
Dict) – The dict of graphs
- Returns:
updated graph
- Return type:
dict
- assets: Dict
- classmethod create_from_iterable(hexagons: List[Hexagon], hypergraph)
Class method to create a polyhex from a number of hexagons
- Parameters:
n_hexagons (
List) – List of hexagons to put in the polyhexhypergraph (
Dict) – Graphs to be recorded.
- Raises:
NotImplementedError – A NotImplementedError is raised when the
hexagonsargument is not a list.- Returns:
Polyhex
- Return type:
polyhex
- classmethod create_from_number(n_hexagons: int, hypergraph: Dict)
Class method to create a polyhex from a number of hexagons
- Parameters:
n_hexagons (
int) – number of hexagons in the polyhexhypergraph (
Dict) – Graphs to be recorded. It requires the HexagonBorderGraph to be recorded.
- Raises:
ValueError – A valueError is raised when the hypergraph does not have a
HexagonBorderGraphkey- Returns:
Polyhex
- Return type:
polyhex
- classmethod create_spiral(radius: int, hypergraph: Dict)
Class method to create a polyhex tiling with a spiral shape. (Think of CATAN’s board)
- Parameters:
radius (
int) – Radius of the spiral tilinghypergraph (
Dict) – Graphs to be recorded. It requires the HexagonBorderGraph to be recorded.
- Raises:
ValueError – A valueError is raised when the hypergraph does not have a
HexagonBorderGraphkey- Returns:
Polyhex
- Return type:
polyhex
- classmethod create_tiling(n: int, m: int, name: str, hypergraph: Dict, **kwargs)
Class method to create a polyhex tiling of size n*m
- Parameters:
n (
int) – Number of rowsm (
int) – Number of columnsname (
str) – Name of the tilinghypergraph (
Dict) – Graphs to be recorded
- Raises:
ValueError – A valueError is raised when the offset
kwargis not even-r or odd-r. See Offset Coordinates in https://www.redblobgames.com/grids/hexagons/NotImplementedError – The tiling can only be rectangular or tilted.
- Returns:
Polyhex tiling (hextille) (see https://en.wikipedia.org/wiki/Hexagonal_tiling)
- Return type:
polyhex
- draw(hypergraph: Dict, save_path='./image.png', buffer=False)
The method to draw a polyhex using a hypergraph.
Note
It is a bit of an abuse to put it as a
polyhexmethod, but it fits the polyhex Orchestrator role- Parameters:
hypergraph (
Dict) – dict of recorded graphssave_path (
str, optional) – Where to save the drawn image. Defaults to “./image.png”.buffer (
bool, optional) – Useful for pygame dynamic rendering. Defaults to False.
- hex_coord_system: str = 'axial'
- placeholder_hex(**kwargs)
The placeholder hexagon is a convenience function used to create a hexagon with attributes similar to the ones already found in the Polyhex. It is used to create the HexagonBorderGraph.
- Returns:
a placeholder hexagon
- Return type:
- radius: int | float = 1
- render(axes, hypergraph: Dict)
The method to render a polyhex using a hypergraph.
Note
It is a bit of an abuse to put it as a
polyhexmethod, but it fits the polyhex Orchestrator role- Parameters:
axes (
matplotlib.axis) – axis on which to render the figurehypergraph (
Dict) – dict of recorded graphs
- top: str = 'pointy'
- vertex_orientation: str = 'clockwise'