def draw_on_pattern(shape, pattern):
    """ Draws a shape on a pattern.

    >>> draw_on_pattern([(0, 0, 1), (0, 1, 3), (1, 1, 8)], [[0, 0, 0], [0, 0, 0]])
    [[1, 3, 0], [0, 8, 0]]
    """

    y_size = len(pattern)
    x_size = len(pattern[0])
    new_pattern = pattern.copy()

    for cell in shape:
        y, x, colour = cell

        if 0 <= y < y_size and 0 <= x < x_size:
            new_pattern[y][x] = colour

    return new_pattern