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()
inAttribute
instances. keyframes, values and correspoing motion types can be added usingappend()
orextend()
. 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 functionf: float -> float
that satisfiesf(0) == 0
andf(1) == 1
. The default isEasing.LINEAR
(linear completion).
- 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 askeyframes
.- easings:
motion types of the keyframes. Each element of
easings
must be a string,Easing
enum, or an easing functionf: float -> float
that satisfiesf(0) == 0
andf(1) == 1
. Note that the length ofeasings
must be the same aslen(keyframes)
orlen(keyframes) - 1
. Ifeasings
isNone
,Easing.LINEAR
is used for all keyframes. Iflen(easings) == len(keyframes) - 1
,Motion
automatically addsEasing.LINEAR
to the end ofeasings
.
- 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