Click here to download the full example code
Timeline and setting keyframes#
In his tutorial, you will learn how to use Fury
Timeline for playing the
Timeline is responsible for handling the playback of Fury Animations.
Timeline has playback methods such as
which can be used to control the animation.
import numpy as np from fury import actor, window from fury.animation import Animation, Timeline
We create our
ShowManager as usual.
scene = window.Scene() showm = window.ShowManager(scene, size=(900, 768)) showm.initialize()
Timeline has the option to attaches a very useful panel for
controlling the animation by setting
Timeline with a PlaybackPanel.
timeline = Timeline(playback_panel=True)
Creating a Fury Animation as usual
anim = Animation() sphere = actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) anim.add_actor(sphere) # Now that the actor is add to the ``Animation``, setting keyframes to the # Animation will animate the actor accordingly.
There are multiple ways to set keyframes:
1- To set a single keyframe, you may use
where <property> is the name of the property to be set. I.e. setting position
to (1, 2, 3) at time 0.0 would be as following:
anim.set_position(0.0, np.array([1, 2, 3]))
Supported properties are: position, rotation, scale, color, and opacity.
2- To set multiple keyframes at once, you may use
That’s it! Now we are done setting keyframes.
In order to control this animation by the timeline we created earlier, this animation must be added to the timeline.
Now we add only the
Timeline to the
ShowManager the same way we add
Animation to the
showm.add_animation(timeline) scene.set_camera(position=(0, 0, -10)) interactive = False if interactive: showm.start() window.record(scene, out_path='viz_keyframe_animation_timeline.png', size=(900, 768))
Total running time of the script: ( 0 minutes 0.116 seconds)