def smooth_color_func(niter, func):
    """Version of :func:`smooth_color` that accepts a function.

    Can be used to pre-calculate a color list outside of a loop.

    Parameters
    ----------
    niter : int
        number of iterations
    func : callable

    Examples
    --------
    >>> from pwtools import mpl
    >>> mpl.smooth_color_func(3, lambda z: (z,0,1-z))
    [(0.0, 0, 1.0), (0.5, 0, 0.5), (1.0, 0, 0.0)]

    >>> for ii,color in enumerate(mpl.smooth_color_func(10, lambda z: (z,0,1-z))):
    ...     plot(rand(20)+ii, color=color)
    """
    col = []
    fniter = float(niter) - 1
    for ii in range(niter):
        z = float(ii) / fniter
        col.append(func(z))
    return col