animation#

Animations module.

Animation(*[, actors, length, loop, ...])

Create and manage keyframe animations for Fury actors.

CameraAnimation(*[, camera, length, loop, ...])

Camera keyframe animation class.

Timeline(*[, animations, playback_panel, ...])

Keyframe animation Timeline.

color_interpolator(keyframes, rgb2space, ...)

Create custom-space color interpolator.

cubic_bezier_interpolator(keyframes)

Create cubic Bézier interpolator for keyframes.

cubic_spline_interpolator(keyframes)

Create cubic spline interpolator for keyframes.

euclidean_distances(points)

Return a list of euclidean distances of a list of points or values.

get_next_timestamp(timestamps, current_time, *)

Return the minimum next timestamp of a given time.

get_previous_timestamp(timestamps, ...[, ...])

Return the maximum previous timestamp of a given time.

get_time_tau(t, t0, t1)

Return a capped time tau between 0 and 1.

get_timestamps_from_keyframes(keyframes)

Return a sorted array of timestamps given dict of keyframes.

get_values_from_keyframes(keyframes)

Return an array of keyframes values sorted using timestamps.

hsv_color_interpolator(keyframes)

Create HSV interpolator for color keyframes.

lab_color_interpolator(keyframes)

Create LAB interpolator for color keyframes.

lerp(v0, v1, t0, t1, t)

Return a linearly interpolated value.

linear_interpolator(keyframes)

Create linear interpolator for keyframes.

slerp(keyframes)

Create spherical based rotation keyframes interpolator.

spline_interpolator(keyframes, degree)

Create N-th degree spline interpolator for keyframes.

step_interpolator(keyframes)

Create step interpolator for keyframes.

tan_cubic_spline_interpolator(keyframes)

Create cubic spline interpolator for keyframes using tangents.

xyz_color_interpolator(keyframes)

Create XYZ interpolator for color keyframes.

Animation#

class fury.animation.Animation(*, actors=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: object

Create and manage keyframe animations for Fury actors.

Animation is responsible for handling keyframe animations for a single actor or a group of actors. It provides control over multiple attributes and properties of Fury actors including position, rotation, scale, color, and opacity. The class also supports custom data interpolation. By default, linear interpolation is used to interpolate data between keyframes.

Parameters:
  • actors (Actor or list of Actor, optional) – Actor(s) to be animated.

  • length (float or int, optional) – The fixed length/duration of the animation in seconds. If None, the animation will derive its duration from the keyframes.

  • loop (bool, optional) – Whether to loop the animation (True) or play once (False).

  • motion_path_res (int, optional) – The number of line segments used to visualize the animation’s motion path (position visualization). Higher values create smoother paths.

__init__(*, actors=None, length=None, loop=True, motion_path_res=None)[source]#

Initialize the Animation.

property actors#

Return a list of actors.

Returns:

List of actors controlled by the Animation.

Return type:

list

add(item)[source]#

Add an item to the Animation.

This item can be an Actor, Animation, list of Actors, or a list of Animations.

Parameters:

item (Animation, vtkActor, list[Animation], or list[vtkActor]) – Actor/s to be animated by the Animation.

add_actor(actor, *, static=False)[source]#

Add an actor or list of actors to the Animation.

Parameters:
  • actor (vtkActor or list(vtkActor)) – Actor/s to be animated by the Animation.

  • static (bool) – Indicated whether the actor should be animated and controlled by the animation or just a static actor that gets added to the scene along with the Animation.

add_child_animation(animation)[source]#

Add child Animation or list of Animations.

Parameters:

animation (Animation or list[Animation]) – Animation/s to be added.

add_static_actor(actor)[source]#

Add static actor(s) which will not be controlled/animated by the Animation.

All static actors will be added to the scene when the Animation is added to the scene.

Parameters:

actor (vtkActor or list(vtkActor)) – Static actor/s.

add_to_scene(scene)[source]#

Add this Animation, its actors and sub Animations to the scene.

Parameters:

scene (fury.window.Scene) – The scene to add the animation, actors, and sub-animations to.

add_to_scene_at(timestamp)[source]#

Set timestamp for adding Animation to scene event.

Parameters:

timestamp (float) – Timestamp of the event when the animation should be added to the scene.

add_update_callback(callback, prop=None)[source]#

Add a function to be called each time animation is updated.

Add a callback function that will be invoked whenever the animation is updated. The function must accept only one argument which is the current value of the named property.

Parameters:
  • callback (callable) – The function to be called whenever the animation is updated.

  • prop (str, optional) – The name of the property.

Notes

If no attribute name was provided, current time of the animation will be provided instead of current value for the callback.

property child_animations: list[Animation]#

Return a list of child Animations.

Returns:

List of child Animations of this Animation.

Return type:

list

property current_timestamp#

Return the current time of the animation.

Returns:

The current time of the animation.

Return type:

float

property duration#

Return the duration of the animation.

Returns:

The duration of the animation.

Return type:

float

get_color(t)[source]#

Return the interpolated color.

Parameters:

t (float) – The time to interpolate color value at.

Returns:

The interpolated color.

Return type:

ndarray, shape (1, 3)

get_current_value(attrib)[source]#

Return the value of an attribute at current time.

Parameters:

attrib (str) – The attribute name.

Returns:

The interpolated value of the attribute at the current timestamp.

Return type:

ndarray or float or bool

get_keyframes(*, attrib=None)[source]#

Get keyframes for a specific or all attributes.

Parameters:

attrib (str, optional) – The name of the attribute. If None, all keyframes for all set attributes will be returned.

Returns:

Dictionary of keyframes for the specified attribute(s).

Return type:

dict

get_opacity(t)[source]#

Return the opacity value.

Parameters:

t (float) – The time to interpolate opacity at.

Returns:

The interpolated opacity.

Return type:

ndarray or float

get_position(t)[source]#

Return the interpolated position.

Parameters:

t (float) – The time to interpolate position at.

Returns:

The interpolated position.

Return type:

ndarray, shape (1, 3)

get_rotation(t, as_quat=False)[source]#

Return the interpolated rotation.

Parameters:
  • t (float) – The time to interpolate rotation at.

  • as_quat (bool) – Returned rotation will be as quaternion if True.

Returns:

The interpolated rotation as Euler degrees by default or as quaternion if as_quat is True.

Return type:

ndarray, shape (1, 3) or shape (1, 4)

get_scale(t)[source]#

Return the interpolated scale.

Parameters:

t (float) – The time to interpolate scale at.

Returns:

The interpolated scale.

Return type:

ndarray, shape (1, 3)

get_value(attrib, timestamp)[source]#

Return the value of an attribute at any given timestamp.

Parameters:
  • attrib (str) – The attribute name.

  • timestamp (float) – The timestamp to interpolate at.

Returns:

The interpolated value of the attribute at the given timestamp.

Return type:

ndarray or float or bool

is_inside_scene_at(timestamp)[source]#

Check if the Animation is set to be inside the scene at a specific timestamp.

Parameters:

timestamp (float) – The timestamp to check scene presence at.

Returns:

True if the Animation is set to be inside the scene at the given timestamp.

Return type:

bool

Notes

If the parent Animation is set to be out of the scene at that time, all of their child animations will be out of the scene as well.

is_interpolatable(attrib)[source]#

Check whether a property is interpolatable.

Parameters:

attrib (str) – The name of the property.

Returns:

True if the property is interpolatable by the Animation.

Return type:

bool

Notes

True means that it’s safe to use Interpolator.interpolate(t) for the specified property. And False means the opposite.

property loop#

Get loop condition of the current animation.

Returns:

Whether the animation in loop mode (True) or play one mode (False).

Return type:

bool

property parent_animation#

Return the hierarchical parent Animation for current Animation.

Returns:

The parent Animation.

Return type:

Animation

remove_actor(actor)[source]#

Remove an actor from the Animation.

Parameters:

actor (vtkActor) – Actor to be removed from the Animation.

remove_actors()[source]#

Remove all actors from the Animation.

remove_animations()[source]#

Remove all child Animations from the Animation.

remove_from_scene(scene)[source]#

Remove Animation, its actors and sub Animations from the scene.

Parameters:

scene (fury.window.Scene) – The scene from which to remove the animation, actors, and sub-animations.

remove_from_scene_at(timestamp)[source]#

Set timestamp for removing Animation from scene event.

Parameters:

timestamp (float) – Timestamp of the event when the animation should be removed from the scene.

set_color(timestamp, color, **kwargs)[source]#

Set color keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • color (ndarray, shape(1, 3)) – Color keyframe value associated with the timestamp.

  • **kwargs (dict, optional) – Additional parameters for the keyframe.

set_color_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the color interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the color keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_color_interpolator(lab_color_interpolator)
set_color_keyframes(keyframes)[source]#

Set a dict of color keyframes at once.

Parameters:

keyframes (dict) – A dict with timestamps as keys and color as values. Should be in the following form: {timestamp_1: color_1, timestamp_2: color_2}.

Examples

>>> import numpy as np
>>> color_keyframes = {1, (1, 0, 1), 3, (0, 0, 1)}
>>> Animation.set_color_keyframes(color_keyframes)
set_interpolator(attrib, interpolator, *, is_evaluator=False, **kwargs)[source]#

Set keyframes interpolator for a certain property.

Parameters:
  • attrib (str) – The name of the property.

  • interpolator (callable) – The generator function of the interpolator to be used to interpolate/evaluate keyframes.

  • is_evaluator (bool, optional) –

    Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes such as:

    def get_position(t):
        return np.array([np.sin(t), np.cos(t) * 5, 5])
    

  • **kwargs (dict, optional) –

    Additional parameters for the interpolator. This can include:

    • spline_degree : int - The degree of the spline in case of setting a spline interpolator.

Notes

If an evaluator is used to set the values of actor’s properties such as position, scale, color, rotation, or opacity, it has to return a value with the same shape as the evaluated property, i.e.: for scale, it has to return an array with shape 1x3, and for opacity, it has to return a 1x1, an int, or a float value.

Examples

>>> Animation.set_interpolator('position', linear_interpolator)
>>> pos_fun = lambda t: np.array([np.sin(t), np.cos(t), 0])
>>> Animation.set_interpolator('position', pos_fun)
set_keyframe(attrib, timestamp, value, *, update_interpolator=True, **kwargs)[source]#

Set a keyframe for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • timestamp (float) – Timestamp of the keyframe.

  • value (ndarray or float or bool) – Value of the keyframe at the given timestamp.

  • update_interpolator (bool, optional) – Interpolator will be reinitialized if True.

  • **kwargs (dict, optional) –

    Additional parameters for the keyframe. This can include:

    • in_cp and out_cp for cubic Bézier interpolation (float).

    • in_tangent and out_tangent for cubic spline interpolation, ndarray, shape (1, M).

set_keyframes(attrib, keyframes)[source]#

Set multiple keyframes for a certain attribute.

Parameters:
  • attrib (str) – The name of the attribute.

  • keyframes (dict) – A dict object containing keyframes to be set.

Notes

Keyframes can be on any of the following forms: >>> import numpy as np >>> key_frames_simple = {1: [1, 2, 1], 2: [3, 4, 5]} >>> key_frames_bezier = {1: {‘value’: [1, 2, 1]}, … 2: {‘value’: [3, 4, 5], ‘in_cp’: [1, 2, 3]}} >>> pos_keyframes = {1: np.array([1, 2, 3]), 3: np.array([5, 5, 5])} >>> Animation.set_keyframes(‘position’, pos_keyframes) # doctest: +SKIP

set_opacity(timestamp, opacity, **kwargs)[source]#

Set opacity keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • opacity (ndarray, shape(1, 3)) – Opacity keyframe value associated with the timestamp.

  • **kwargs (dict) – Additional parameters for the keyframe.

set_opacity_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the opacity interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the opacity keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_opacity_interpolator(step_interpolator)
set_opacity_keyframes(keyframes)[source]#

Set a dict of opacity keyframes at once.

Parameters:

keyframes (dict) – A dict with timestamps as keys and opacities as values. Should be in the following form: {timestamp_1: opacity_1, timestamp_2: opacity_2}.

Notes

Opacity values should be between 0 and 1.

Examples

>>> opacity = {1, (1, 1, 1), 3, (2, 2, 3)}
>>> Animation.set_scale_keyframes(opacity)
set_position(timestamp, position, **kwargs)[source]#

Set a position keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • position (ndarray, shape (1, 3)) – Position value.

  • **kwargs (dict, optional) –

    Additional parameters for the keyframe. This can include:

    • in_cp and out_cp for cubic Bézier interpolation (float).

    • in_tangent and out_tangent for cubic spline interpolation, ndarray, shape (1, M).

Notes

in_cp and out_cp only needed when using the cubic bezier interpolation method.

set_position_interpolator(interpolator, *, is_evaluator=False, **kwargs)[source]#

Set the position interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

  • **kwargs (dict, optional) –

    Additional parameters for the interpolator. This can include:

    • degree : int - The degree of the spline interpolation in case of setting the spline_interpolator.

set_position_keyframes(keyframes)[source]#

Set a dict of position keyframes at once.

Parameters:

keyframes (dict) – A dict with timestamps as keys and positions as values. Should be in the following form: {timestamp_1: position_1, timestamp_2: position_2}.

Examples

>>> pos_keyframes = {1, (0, 0, 0), 3, (50, 6, 6)}
>>> Animation.set_position_keyframes(pos_keyframes)
set_rotation(timestamp, rotation, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • rotation (ndarray, shape(1, 3) or shape(1, 4)) – Rotation data in euler degrees with shape(1, 3) or in quaternions with shape(1, 4).

  • **kwargs (dict, optional) – Additional parameters for the keyframe.

Notes

Euler rotations are executed by rotating first around Z then around X, and finally around Y.

set_rotation_as_vector(timestamp, vector, **kwargs)[source]#

Set a rotation keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • vector (ndarray, shape(1, 3)) – Directional vector that describes the rotation.

  • **kwargs (dict, optional) – Additional parameters for the keyframe.

set_rotation_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the rotation interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the rotation (orientation) keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_rotation_interpolator(slerp)
set_scale(timestamp, scalar, **kwargs)[source]#

Set a scale keyframe at a specific timestamp.

Parameters:
  • timestamp (float) – Timestamp of the keyframe.

  • scalar (ndarray, shape(1, 3)) – Scale keyframe value associated with the timestamp.

  • **kwargs (dict, optional) – Additional parameters for the keyframe.

set_scale_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the scale interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the scale keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

Examples

>>> Animation.set_scale_interpolator(step_interpolator)
set_scale_keyframes(keyframes)[source]#

Set a dict of scale keyframes at once.

Parameters:

keyframes (dict) – A dict with timestamps as keys and scales as values. Should be in the following form: {timestamp_1: scale_1, timestamp_2: scale_2}.

Examples

>>> scale_keyframes = {1, (1, 1, 1), 3, (2, 2, 3)}
>>> Animation.set_scale_keyframes(scale_keyframes)
property static_actors#

Return a list of static actors.

Returns:

List of static actors.

Return type:

list

property timeline#

Return the Timeline handling the current animation.

Returns:

The Timeline handling the current animation, None, if there is no associated Timeline.

Return type:

Timeline

update_animation(*, time=None)[source]#

Update the animation.

Update the animation at a certain time. This will make sure all attributes are calculated and set to the actors at that given time.

Parameters:

time (float or int, optional) – The time to update animation at. If None, the animation will play without adding it to a Timeline.

update_duration()[source]#

Update and return the duration of the Animation.

Update the animation duration based on the length parameter or the maximum timestamp of all keyframes and child animations.

Returns:

The duration of the animation in seconds.

Return type:

float

update_motion_path()[source]#

Update motion path visualization actor.

Creates or updates the motion path visualization actor that represents the animation path. The resolution of the path is determined by motion_path_res.

CameraAnimation#

class fury.animation.CameraAnimation(*, camera=None, length=None, loop=True, motion_path_res=None)[source]#

Bases: Animation

Camera keyframe animation class.

This is used for animating a single camera using a set of keyframes.

Parameters:
  • camera (Camera, optional) – Camera to be animated. If None, active camera will be animated.

  • length (float or int, optional) – The fixed length/duration of the animation in seconds. If None, the animation will derive its duration from the keyframes.

  • loop (bool, optional) – Whether to loop the animation (True) or play once (False).

  • motion_path_res (int, optional) – The number of line segments used to visualize the animation’s motion path (position visualization). Higher values create smoother paths.

camera#

Camera being animated by the CameraAnimation.

Type:

Camera

duration#

The duration of the animation in seconds.

Type:

float

loop#

Whether the animation is in loop mode (True) or play one mode (False).

Type:

bool

__init__(*, camera=None, length=None, loop=True, motion_path_res=None)[source]#

Initialize CameraAnimation.

get_focal(t)[source]#

Return the interpolated camera’s focal position.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera’s focal position.

Return type:

ndarray, shape (1, 3)

Notes

The returned focal position does not necessarily reflect the current camera’s focal position, but the expected one.

get_view_up(t)[source]#

Return the interpolated camera’s view-up directional vector.

Parameters:

t (float) – The time to interpolate at.

Returns:

The interpolated camera view-up directional vector.

Return type:

ndarray, shape (1, 3)

Notes

The returned focal position does not necessarily reflect the actual camera view up directional vector, but the expected one.

set_focal(timestamp, position, **kwargs)[source]#

Set camera’s focal position keyframe.

Parameters:
  • timestamp (float) – The time to set the keyframe at.

  • position (ndarray, shape (1, 3)) – The camera focal position.

  • **kwargs (dict, optional) –

    Additional keyword arguments for the keyframe. The following parameters are supported:

    • in_cp: ndarray - The in control point for cubic Bézier interpolation.

    • out_cp: ndarray - The out control point for cubic Bézier interpolation.

    • in_tangent: ndarray - The in tangent at that position for cubic spline curve.

    • out_tangent: ndarray - The out tangent at that position for cubic spline curve.

set_focal_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the camera focal position interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera focal position keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_focal_keyframes(keyframes)[source]#

Set multiple camera focal position keyframes at once.

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera focal positions as values. Should be in the following form: {timestamp_1: focal_1, timestamp_2: focal_1, …}.

Examples

>>> focal_pos = {0, (1, 1, 1), 3, (20, 0, 0)}
>>> CameraAnimation.set_focal_keyframes(focal_pos)
set_view_up(timestamp, direction, **kwargs)[source]#

Set the camera view-up direction keyframe.

Parameters:
  • timestamp (float) – The time to set the keyframe at.

  • direction (ndarray, shape (1, 3)) – The camera view-up direction vector.

  • **kwargs (dict, optional) –

    Additional keyword arguments for the keyframe. The following parameters are supported:

    • in_cp: ndarray - The in control point for cubic Bézier interpolation.

    • out_cp: ndarray - The out control point for cubic Bézier interpolation.

    • in_tangent: ndarray - The in tangent at that position for cubic spline curve.

    • out_tangent: ndarray - The out tangent at that position for cubic spline curve.

set_view_up_interpolator(interpolator, *, is_evaluator=False)[source]#

Set the camera up-view vector animation interpolator.

Parameters:
  • interpolator (callable) – The generator function of the interpolator that would handle the interpolation of the camera view-up keyframes.

  • is_evaluator (bool, optional) – Specifies whether the interpolator is time-only based evaluation function that does not depend on keyframes.

set_view_up_keyframes(keyframes)[source]#

Set multiple camera view up direction keyframes.

Parameters:

keyframes (dict) – A dict with timestamps as keys and camera view up vectors as values. Should be in the following form: {timestamp_1: view_up_1, timestamp_2: view_up_2, …}.

Examples

>>> view_ups = {0: np.array([1, 0, 0]), 3: np.array([0, 1, 0])}
>>> CameraAnimation.set_view_up_keyframes(view_ups)
update_animation(*, time=None)[source]#

Update the camera animation.

Parameters:

time (float or int, optional) – The time to update the camera animation at. If None, the animation will play.

Timeline#

class fury.animation.Timeline(*, animations=None, playback_panel=False, loop=True, length=None)[source]#

Bases: object

Keyframe animation Timeline.

Timeline is responsible for handling the playback of keyframes animations. It has multiple playback options which makes it easy to control the playback, speed, state of the animation with/without a GUI playback panel.

Parameters:
  • animations (Animation or list[Animation], optional) – Actor/s to be animated directly by the Timeline (main Animation). Default is None.

  • playback_panel (bool, optional) – If True, the timeline will have a playback panel set, which can be used to control the playback of the timeline. Default is False.

  • loop (bool, optional) – Whether to loop playing the timeline or play once. Default is True.

  • length (float or int, optional) – The fixed length of the timeline. If set to None, the timeline will get its length from the animations that it controls automatically. Default is None.

playback_panel#

The panel used to control the playback of the timeline.

Type:

PlaybackPanel or None

__init__(*, animations=None, playback_panel=False, loop=True, length=None)[source]#

Initialize the Timeline.

add_animation(animation)[source]#

Add Animation or list of Animations to the Timeline.

Parameters:

animation (Animation or list[Animation] or tuple[Animation]) – Animation object(s) to be added to this Timeline.

Raises:

TypeError – If the provided animation is not an Animation object or a collection of Animation objects.

add_to_scene(scene)[source]#

Add Timeline and all of its Animations to the scene.

Parameters:

scene (fury.window.Scene) – The scene to add the Timeline and its Animations to.

property animations: list[Animation]#

Return all animations controlled by this Timeline.

Returns:

List of Animation objects controlled by the timeline.

Return type:

list

property current_timestamp#

Get current timestamp of the Timeline.

Returns:

The current position in seconds of the Timeline.

Return type:

float

property duration#

Return the duration of the Timeline.

Returns:

The duration of the Timeline in seconds.

Return type:

float

property has_playback_panel#

Return whether the Timeline has a playback panel.

Returns:

True if the Timeline has a playback panel, False otherwise.

Return type:

bool

property loop#

Return the loop setting of the timeline.

Returns:

True if the timeline is set to loop playback, False if set to play once.

Return type:

bool

pause()[source]#

Pause the animation.

Freeze the animation at its current timestamp.

property paused#

Return whether the Timeline is paused.

Returns:

True if the Timeline is paused (not playing but at a non-zero timestamp), False otherwise.

Return type:

bool

play()[source]#

Play the animation.

Start playing the timeline from the current timestamp. If the current timestamp is at the end of the timeline, it will reset to the beginning.

property playing#

Return whether the Timeline is playing.

Returns:

True if the Timeline is currently playing, False otherwise.

Return type:

bool

record(*, fname=None, fps=30, speed=1.0, size=(900, 768), order_transparent=True, multi_samples=8, max_peels=4, show_panel=False)[source]#

Record the animation to a file or return frames.

Parameters:
  • fname (str, optional) – The output filename. Creates a GIF if name ends with ‘.gif’, or an MP4 video if name ends with ‘.mp4’. If None, only returns the frames array. Default is None.

  • fps (int, optional) – The number of frames per second to record. Default is 30.

  • speed (float, optional) – The playback speed multiplier for the recording. Default is 1.0.

  • size (tuple of int, optional) – The dimensions of the recording as (width, height). Default is (900, 768).

  • order_transparent (bool, optional) – Whether to use depth peeling to sort transparent objects. If True, also enables anti-aliasing. Default is True.

  • multi_samples (int, optional) – Number of samples for anti-aliasing. Use 0 for no anti-aliasing. Default is 8.

  • max_peels (int, optional) – Maximum number of peels for depth peeling. Default is 4.

  • show_panel (bool, optional) – Controls whether to show the playback panel (if True) or hide it (if False) in the recording. Default is False.

Returns:

List of frames as PIL Image objects.

Return type:

list

Notes

It’s recommended to use 30 or 50 FPS when recording to a GIF file. To save as MP4, OpenCV must be installed.

remove_from_scene(scene)[source]#

Remove Timeline and all of its Animations from the scene.

Parameters:

scene (fury.window.Scene) – The scene from which to remove the Timeline and its Animations.

restart()[source]#

Restart the animation.

Reset the timeline to the beginning and start playing.

seek(timestamp)[source]#

Set the current timestamp of the Timeline.

Parameters:

timestamp (float) – The time in seconds to seek to. Will be clamped between 0 and the timeline duration.

seek_percent(percent)[source]#

Seek to a percentage of the Timeline’s duration.

Parameters:

percent (float) – Percentage value from 0 to 100 of the timeline duration to seek to.

property speed#

Return the speed of the timeline’s playback.

Returns:

The playback speed multiplier.

Return type:

float

stop()[source]#

Stop the animation.

Reset the timeline to the beginning and stop playback.

property stopped#

Return whether the Timeline is stopped.

Returns:

True if the Timeline is stopped (not playing and at timestamp 0), False otherwise.

Return type:

bool

update(*, force=False)[source]#

Update the timeline and all controlled animations.

Updates the Timeline and all animations it controls. Also updates the playback panel if one exists.

Parameters:

force (bool, optional) – If True, the timeline will update even when paused or stopped, which may use more resources. Default is False.

update_duration()[source]#

Update and return the duration of the Timeline.

Calculate the duration based on either a fixed length or the maximum duration of all animations controlled by this Timeline.

Returns:

The duration of the Timeline in seconds.

Return type:

float

color_interpolator#

fury.animation.color_interpolator(keyframes, rgb2space, space2rgb)[source]#

Create custom-space color interpolator.

Interpolate values linearly inside a custom color space.

Parameters:
  • keyframes (dict) – Color keyframes to be interpolated at any time.

  • rgb2space (function) – A function that takes color value in rgb and returns that color converted to the targeted space.

  • space2rgb (function) – A function that takes color value in the targeted space and returns that color in rgb space.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

cubic_bezier_interpolator#

fury.animation.cubic_bezier_interpolator(keyframes)[source]#

Create cubic Bézier interpolator for keyframes.

This is a general cubic Bézier interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframes to be interpolated at any time.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Notes

If no control points are set in the keyframes, The cubic Bézier interpolator will almost behave as a linear interpolator.

cubic_spline_interpolator#

fury.animation.cubic_spline_interpolator(keyframes)[source]#

Create cubic spline interpolator for keyframes.

This is a general cubic spline interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the cubic spline curve.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

See also

spline_interpolator

N-th degree spline interpolator.

euclidean_distances#

fury.animation.euclidean_distances(points)[source]#

Return a list of euclidean distances of a list of points or values.

Parameters:

points (ndarray) – Array of points or valued to calculate euclidean distances between.

Returns:

A List of euclidean distance between each consecutive points or values.

Return type:

list

get_next_timestamp#

fury.animation.get_next_timestamp(timestamps, current_time, *, include_first=False)[source]#

Return the minimum next timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_first (bool, optional) – If True, even the first timestamp will be considered a valid next timestamp.

Returns:

The next timestamp.

Return type:

float or int

get_previous_timestamp#

fury.animation.get_previous_timestamp(timestamps, current_time, *, include_last=False)[source]#

Return the maximum previous timestamp of a given time.

Parameters:
  • timestamps (ndarray) – Sorted list of timestamps.

  • current_time (float or int) – The time to get previous timestamp for.

  • include_last (bool, optional) – If True, even the last timestamp will be considered a valid previous timestamp.

Returns:

The previous timestamp.

Return type:

float or int

get_time_tau#

fury.animation.get_time_tau(t, t0, t1)[source]#

Return a capped time tau between 0 and 1.

Parameters:
  • t (float or int) – Current time to calculate tau for.

  • t0 (float or int) – Lower timestamp of the time period.

  • t1 (float or int) – Higher timestamp of the time period.

Returns:

The time tau.

Return type:

float

get_timestamps_from_keyframes#

fury.animation.get_timestamps_from_keyframes(keyframes)[source]#

Return a sorted array of timestamps given dict of keyframes.

Parameters:

keyframes (dict) – Keyframes dict that contains timestamps as keys.

Returns:

Array of sorted timestamps extracted from the keyframes.

Return type:

ndarray

get_values_from_keyframes#

fury.animation.get_values_from_keyframes(keyframes)[source]#

Return an array of keyframes values sorted using timestamps.

Parameters:

keyframes (dict) – Keyframes dict that contains timestamps as keys and data as values.

Returns:

Array of sorted values extracted from the keyframes.

Return type:

ndarray

hsv_color_interpolator#

fury.animation.hsv_color_interpolator(keyframes)[source]#

Create HSV interpolator for color keyframes.

Parameters:

keyframes (dict) – Color keyframes in RGB space to be interpolated.

Returns:

The interpolation function that take time and return interpolated color value at that time in RGB space.

Return type:

function

See also

color_interpolator

General color space interpolator.

lab_color_interpolator#

fury.animation.lab_color_interpolator(keyframes)[source]#

Create LAB interpolator for color keyframes.

Parameters:

keyframes (dict) – Color keyframes in RGB space to be interpolated.

Returns:

The interpolation function that take time and return interpolated color value at that time in RGB space.

Return type:

function

See also

color_interpolator

General color space interpolator.

lerp#

fury.animation.lerp(v0, v1, t0, t1, t)[source]#

Return a linearly interpolated value.

Parameters:
  • v0 (ndarray or float or int) – The first value.

  • v1 (ndarray or float or int) – The second value.

  • t0 (float or int) – Timestamp associated with v0.

  • t1 (float or int) – Timestamp associated with v1.

  • t (float or int) – Current time to interpolate at.

Returns:

The interpolated value.

Return type:

ndarray or float

linear_interpolator#

fury.animation.linear_interpolator(keyframes)[source]#

Create linear interpolator for keyframes.

This is a general linear interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data to be linearly interpolated.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

slerp#

fury.animation.slerp(keyframes)[source]#

Create spherical based rotation keyframes interpolator.

A rotation interpolator to be used for rotation keyframes.

Parameters:

keyframes (dict) – Rotation keyframes to be interpolated at any time.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Notes

Rotation keyframes must be in the form of quaternions.

spline_interpolator#

fury.animation.spline_interpolator(keyframes, degree)[source]#

Create N-th degree spline interpolator for keyframes.

This is a general n-th degree spline interpolator to be used for any shape of keyframes data.

Parameters:
  • keyframes (dict) – Keyframe data containing timestamps and values to form the spline curve. Data should be on the following format: {1: {‘value’: np.array([…])}, 2: {‘value’: np.array([…])}}.

  • degree (int) – The degree of the spline.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

Raises:

ValueError – If the number of keyframes is less than degree + 1.

step_interpolator#

fury.animation.step_interpolator(keyframes)[source]#

Create step interpolator for keyframes.

This is a simple step interpolator to be used for any shape of keyframes data.

Parameters:

keyframes (dict) – Keyframe data containing timestamps and values to form the spline.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

tan_cubic_spline_interpolator#

fury.animation.tan_cubic_spline_interpolator(keyframes)[source]#

Create cubic spline interpolator for keyframes using tangents.

glTF contains additional tangent information for the cubic spline interpolator.

Parameters:

keyframes (dict) – Keyframe data containing timestamps, values, and tangents to form the cubic spline curve.

Returns:

The interpolation function that take time and return interpolated value at that time.

Return type:

function

xyz_color_interpolator#

fury.animation.xyz_color_interpolator(keyframes)[source]#

Create XYZ interpolator for color keyframes.

Parameters:

keyframes (dict) – Color keyframes in RGB space to be interpolated.

Returns:

The interpolation function that take time and return interpolated color value at that time in RGB space.

Return type:

function

See also

color_interpolator

General color space interpolator.