def my_fill(draw, num_point, points, color):
    x_min = x_max = points[0][0]
    y_min = y_max = points[0][1]
    border_points = {}
    for i in range(1, num_point + 1):
        x_min = min(x_min, points[i][0])
        y_min = min(y_min, points[i][1])
        x_max = max(x_max, points[i][0])
        y_max = max(y_max, points[i][1])
        line_points = get_points(points[i - 1][0],
                                 points[i - 1][1],
                                 points[i][0],
                                 points[i][1])
        for i in range(len(line_points) - 1):
            if not (line_points[i][0] == line_points[i + 1][0] and
                    line_points[i][1] == (line_points[i + 1][1] + 1)):
                border_points.setdefault(line_points[i][0],
                                         []).append(line_points[i][1])
    for i in range(x_min, x_max):
        try:
            while True:
                print border_points[i]
                y1 = border_points[i].pop(0)
                y2 = border_points[i].pop()
                draw.line([i, y1, i, y2], color)
        except IndexError:
            pass
def tri_by_tri(draw, x1, y1, x2, y2, x3, y3, color):
    mid_1_2 = [(x1 + x2) / 2, (y1 + y2) / 2]
    mid_2_3 = [(x2 + x3) / 2, (y2 + y3) / 2]
    mid_1_3 = [(x1 + x3) / 2, (y1 + y3) / 2]

    points_1_to_2_3 = get_points(x1, y1, *mid_2_3)
    points_2_to_1_3 = get_points(x2, y2, *mid_1_3)
    points_3_to_1_2 = get_points(x3, y3, *mid_1_2)

    while points_1_to_2_3 and points_2_to_1_3 and points_3_to_1_2:
        draw.line([x1, y1, x2, y2], color)
        draw.line([x2, y2, x3, y3], color)
        draw.line([x1, y1, x3, y3], color)

        x1, y1 = points_1_to_2_3.pop()
        x2, y2 = points_2_to_1_3.pop()
        x3, y3 = points_3_to_1_2.pop()