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
Attributeinstances used for keyframe animations.This instance is basically initialized by calling
enable_motion()inAttributeinstances. keyframes, values and correspoing motion types can be added usingappend()orextend(). By using these keyframes,Motioninstance 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
Attributewill 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,
Easingenum, or an easing functionf: float -> floatthat satisfiesf(0) == 0andf(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
valuesmust be the same askeyframes.- easings:
motion types of the keyframes. Each element of
easingsmust be a string,Easingenum, or an easing functionf: float -> floatthat satisfiesf(0) == 0andf(1) == 1. Note that the length ofeasingsmust be the same aslen(keyframes)orlen(keyframes) - 1. IfeasingsisNone,Easing.LINEARis used for all keyframes. Iflen(easings) == len(keyframes) - 1,Motionautomatically addsEasing.LINEARto 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