def solve(maze, start, end):

    matrix = generate_matrix(maze, len(maze[0]), len(maze))
    result = [(None, inf)]
    dfs_rec(matrix[start[0]][start[1]], [], matrix[end[0]][end[1]], result, 0)

    LEN = 40
    im = Svg("maze.svg")
    for x in range(len(maze[0])):
        for y in range(len(maze)):
            color = "white"
            if maze[x][y] == 1:
                color = "gray"
            if (x, y) == start or (x, y) == end:
                color = "blue"
            im.rectangle(x * LEN, y * LEN, LEN, LEN, fill=color)
    prew = matrix[start[0]][start[1]]
    for point in result[0][0][1:]:
        x1, y1 = prew.position
        x2, y2 = point.position
        im.line(x1 * LEN + LEN // 2, y1 * LEN - LEN // 2, x2 * LEN + LEN // 2,
                y2 * LEN - LEN // 2, "red")
        prew = point

    im.close()
示例#2
0
def print_pascal(p, d, size, color_f):

    size = 10
    im = Svg("pascal.svg")

    for line in p:
        count = len(line)
        left_offset = count * size * -0.5
        for i in range(count):
            im.rectangle(left_offset + i * size,
                         -(count - 1) * size,
                         size,
                         size,
                         fill=color_f(d, line[i]))

    im.close()