1import numpy as np
2
3
4def fadein(clip, duration, initial_color=None):
5    """
6    Makes the clip progressively appear from some color (black by default),
7    over ``duration`` seconds at the beginning of the clip. Can be used for
8    masks too, where the initial color must be a number between 0 and 1.
9    For cross-fading (progressive appearance or disappearance of a clip
10    over another clip, see ``composition.crossfade``
11    """
12
13    if initial_color is None:
14        initial_color = 0 if clip.ismask else [0,0,0]
15
16    initial_color = np.array(initial_color)
17
18    def fl(gf, t):
19        if t>=duration:
20            return gf(t)
21        else:
22            fading = (1.0*t/duration)
23            return fading*gf(t) + (1-fading)*initial_color
24
25    return clip.fl(fl)
26