def interpolate(col1, col2, ni):
    """
    Linear interpolation between two adjacent colors in color palette.
    """

    f = ni % 1  # fractional part of ni
    r = (col2[0] - col1[0]) * f + col1[0]
    g = (col2[1] - col1[1]) * f + col1[1]
    b = (col2[2] - col1[2]) * f + col1[2]
    return [r, g, b]