thorvg_python.animation¶
-
class thorvg_python.animation.Animation(engine: Engine, animation: AnimationStruct | None =
None)¶ Bases:
objectAnimation API
A module for manipulation of animatable images.
The module supports the display and control of animation frames.
- get_duration() tuple[Result, float]¶
Retrieves the duration of the animation in seconds.
- Returns:¶
INVALID_ARGUMENT An invalid AnimationStruct pointer or
duration.- Return type:¶
- Returns:¶
The duration of the animation in seconds.
- Return type:¶
float
Note
If the Picture is not properly configured, this function will return 0.
Added in version 0.13.
- get_frame() tuple[Result, float]¶
Retrieves the current frame number of the animation.
- Returns:¶
INVALID_ARGUMENT An invalid AnimationStruct pointer or
no- Return type:¶
- Returns:¶
The current frame number of the animation, between 0 and totalFrame() - 1.
- Return type:¶
float
See also
Animation.get_total_frame()
See also
Animation.set_frame()
Added in version 0.13.
- get_picture() Picture¶
Retrieves a picture instance associated with this animation instance.
This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames with this Animation instance.
Warning
The picture instance is owned by Animation. It should not be deleted manually.
Added in version 0.13.
- get_segment() tuple[Result, float, float]¶
Gets the current segment.
- Returns:¶
INSUFFICIENT_CONDITION In case the animation is not loaded.
INVALID_ARGUMENT When the given parameters are
nullptr.
- Return type:¶
- Returns:¶
segment begin.
- Return type:¶
float
- Returns:¶
segment end.
- Return type:¶
float
Note
Experimental API
- get_total_frame() tuple[Result, float]¶
Retrieves the total number of frames in the animation.
- Returns:¶
INVALID_ARGUMENT An invalid AnimationStruct pointer or
cnt.- Return type:¶
- Returns:¶
The total number of frames in the animation.
- Return type:¶
float
Note
Frame numbering starts from 0.
Note
If the Picture is not properly configured, this function will return 0.
Added in version 0.13.
- set_frame(no: float) Result¶
Specifies the current frame in the animation.
- Parameters:¶
- no : float¶
The index of the animation frame to be displayed. The index should be less than the Animation.get_total_frame().
- Returns:¶
INVALID_ARGUMENT An invalid AnimationStruct pointer.
INSUFFICIENT_CONDITION if the given
nois the same as the current frame value.NOT_SUPPORTED The picture data does not support animations.
- Return type:¶
Note
For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value is less than 0.001. In such cases, it returns
Result::InsufficientCondition. Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.See also
Animation.get_total_frame()
Added in version 0.13.