예제 #1
0
def main():
    # grid = Grid(coordinate_system=OFFSET, hexagon_type=FLAT)

    # grid[-1, -1] = None
    # grid[-1, 0] = None
    # grid[0, 0] = None
    # grid[0, 1] = None
    # grid[1, 0] = None
    # grid[1, 1] = None
    # grid[1, 2] = None
    # path = grid.shortest_path_coordinates((-1, -1), (1, 2))
    # print(path)

    grid = Grid(hexagon_type=HexagonType.FLAT,
                coordinate_system=CoordinateSystem.CUBIC)

    for i in range(-3, 4):
        for j in range(-3, 4):
            c = Grid.convert((i, j), CoordinateSystem.AXIAL,
                             CoordinateSystem.CUBIC)
            grid[c] = None

    path = grid.shortest_path_coordinates((-3, 2, 1), (3, -2, -1))

    draw = DrawGrid(grid)
    draw.draw_hexagons(grid.keys(), labels=True, fill='#7070ff')
    draw.draw_hexagons(path, labels=True, fill='#ff7070')
    draw.draw()
예제 #2
0
def main():
    g = Grid(hexagon_type=HexagonType.FLAT, coordinate_system=CoordinateSystem.CUBIC)

    for i in range(-3, 4):
        for j in range(-3, 4):
            c = Grid.convert((i, j), CoordinateSystem.AXIAL, CoordinateSystem.CUBIC)
            g[c] = None

    # g = Grid(HexagonType.FLAT, CoordinateSystem.AXIAL)
    # for i in range(5):
    #     for j in range(5):
    #         g[i, j] = None

    draw_obj = DrawGrid(g)
    draw_obj.draw_hexagons(g.keys(), labels=True, fill='#7070ff')
    draw_obj.draw()
예제 #3
0
def main():
    grid = Grid(coordinate_system=OFFSET, hexagon_type=FLAT)

    grid[-1, -1] = None
    grid[0, 0] = None
    grid[0, 1] = None
    grid[1, 0] = None
    grid[1, 1] = None
    grid[1, 2] = None

    neighbors = grid.neighbor_coordinates((0, 0))

    line = grid.line_coordinates((0, 0), (4, 4), validate=False)

    draw = DrawGrid(grid)
    draw.draw_hexagons(grid.keys(), labels=True, fill='#7070ff')
    draw.draw_hexagons(neighbors, labels=True, fill='#ff7070')
    draw.draw_hexagons(line, labels=True, fill='#70ff70')
    draw.draw()
예제 #4
0
 def test_set_coordinate(self):
     g = Grid()
     g[0, 0] = None
     g.set_coordinate_system(CUBIC)
     coord = tuple(g.keys())[0]
     self.assertSequenceEqual(coord, (0, 0, 0))