movis.motion.Motion#

class movis.motion.Motion(init_value: float | Sequence[float] | ndarray | None = None, value_type: AttributeType = AttributeType.SCALAR)[source]#

Defines a motion of Attribute instances used for keyframe animations.

This instance is basically initialized by calling enable_motion() in Attribute instances. keyframes, values and correspoing motion types can be added using append() or extend(). By using these keyframes, Motion instance returns the complemented values at the given time.

Args:
init_value:

The initial value to use. It is used when no animation is set, or when an animation with zero keyframes is set.

value_type:

Specifies the type of value that the Attribute will handle.

Examples:
>>> import movis as mv
>>> attr = mv.Attribute(1.0, mv.AttributeType.SCALAR)
>>> attr.enable_motion().append(0.0, 0.0).append(1.0, 1.0)
>>> len(attr.motion)
2
>>> attr.enable_motion().extend([2.0, 3.0], [2.0, 3.0], ['ease_in_out'])
>>> len(attr.motion)
4
>>> attr.motion.clear()
>>> len(attr.motion)
0
>>> assert attr(0.0) == attr.init_value

Methods

append(keyframe: float, value: float | Sequence[float] | ndarray, easing: str | Easing | Callable[[float], float] = Easing.LINEAR) Motion[source]#

Append a single keyframe.

Args:
keyframe:

time of the keyframe.

value:

value of the keyframe.

easing:

motion type of the keyframe. This must be a string, Easing enum, or an easing function f: float -> float that satisfies f(0) == 0 and f(1) == 1. The default is Easing.LINEAR (linear completion).

clear() Motion[source]#
extend(keyframes: Sequence[float], values: Sequence[float | Sequence[float] | ndarray], easings: Sequence[str | Easing | Callable[[float], float]] | None = None) Motion[source]#

Append multiple keyframes.

Args:
keyframes:

times of the keyframes.

values:

values of the keyframes. The length of values must be the same as keyframes.

easings:

motion types of the keyframes. Each element of easings must be a string, Easing enum, or an easing function f: float -> float that satisfies f(0) == 0 and f(1) == 1. Note that the length of easings must be the same as len(keyframes) or len(keyframes) - 1. If easings is None, Easing.LINEAR is used for all keyframes. If len(easings) == len(keyframes) - 1, Motion automatically adds Easing.LINEAR to the end of easings.

Examples:
>>> import movis as mv
>>> motion = mv.Motion(value_type=mv.AttributeType.SCALAR)
>>> # add two keyframes and The type of motion for that period is ``Easing.EASE_IN_OUT``
>>> motion.extend(keyframes=[0.0, 1.0], values=[0.0, 1.0], easings=['ease_in_out'])
>>> # add other two keyframes and The type of motion for that period is ``Easing.LINEAR``
>>> motion.extend([2.0, 3.0], [2.0, 3.0])
>>> len(motion)
4