movis.ops.fade_in_out#

movis.ops.fade_in_out(layer: BasicLayer, fade_in: float = 0.0, fade_out: float = 0.0, size: tuple[int, int] | None = None, bg_color: tuple[int, int, int] | str | None = None) Composition[source]#

Fade in and out a layer. If fade_in or fade_out is 0.0, the corresponding effect is not applied.

Args:
layer:

Layer to fade in and out.

fade_in:

Duration of the fade-in effect.

fade_out:

Duration of the fade-out effect.

size:

Size of the composition. If None, the size of the layer is estimated.

bg_color:

Background color. If None, the background is transparent.

Returns:

Composition with the layer faded in and out.

Examples:
>>> import movis as mv
>>> layer = mv.layer.Image.from_color((10, 10), "white", duration=3.0)
>>> composition = mv.fade_in_out(layer, fade_in=1.0, fade_out=1.0)
>>> composition(0.0)[0, 0, :]
array([0, 0, 0, 0], dtype=uint8)
>>> composition(1.0)[0, 0, :]
array([255, 255, 255, 255], dtype=uint8)
>>> composition(2.0)[0, 0, :]
array([255, 255, 255, 255], dtype=uint8)
>>> composition(3.0 - 1e-5)[0, 0, :]
array([0, 0, 0, 0], dtype=uint8)