.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_timeline.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_animation_viz_timeline.py: ============================== Timeline and setting keyframes ============================== In his tutorial, you will learn how to use Fury ``Timeline`` for playing the animations. .. GENERATED FROM PYTHON SOURCE LINES 11-18 What is ``Timeline``? ===================== ``Timeline`` is responsible for handling the playback of Fury Animations. ``Timeline`` has playback methods such as ``play``, ``pause``, ``stop``, ... which can be used to control the animation. .. GENERATED FROM PYTHON SOURCE LINES 18-25 .. code-block:: Python import numpy as np from fury import actor, window from fury.animation import Animation, Timeline .. GENERATED FROM PYTHON SOURCE LINES 26-27 We create our ``Scene`` and ``ShowManager`` as usual. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python scene = window.Scene() showm = window.ShowManager(scene, size=(900, 768)) showm.initialize() .. GENERATED FROM PYTHON SOURCE LINES 33-38 Creating a ``Timeline`` ======================= FURY ``Timeline`` has the option to attaches a very useful panel for controlling the animation by setting ``playback_panel=True``. .. GENERATED FROM PYTHON SOURCE LINES 40-41 Creating a ``Timeline`` with a PlaybackPanel. .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Creating a Fury Animation as usual .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. code-block:: Python 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. .. GENERATED FROM PYTHON SOURCE LINES 53-61 Setting Keyframes ================= There are multiple ways to set keyframes: 1- To set a single keyframe, you may use ``animation.set_(t, k)``, where 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: .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python anim.set_position(0.0, np.array([1, 2, 3])) .. GENERATED FROM PYTHON SOURCE LINES 64-68 Supported properties are: **position, rotation, scale, color, and opacity**. 2- To set multiple keyframes at once, you may use ``animation.set__keyframes(keyframes)``. .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python keyframes = {1.0: np.array([0, 0, 0]), 3.0: np.array([-2, 0, 0])} anim.set_position_keyframes(keyframes) .. GENERATED FROM PYTHON SOURCE LINES 73-74 That's it! Now we are done setting keyframes. .. GENERATED FROM PYTHON SOURCE LINES 76-78 In order to control this animation by the timeline we created earlier, this animation must be added to the timeline. .. GENERATED FROM PYTHON SOURCE LINES 78-80 .. code-block:: Python timeline.add_animation(anim) .. GENERATED FROM PYTHON SOURCE LINES 81-83 Now we add only the ``Timeline`` to the ``ShowManager`` the same way we add ``Animation`` to the ``ShowManager``. .. GENERATED FROM PYTHON SOURCE LINES 83-93 .. code-block:: Python 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)) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_timeline_001.png :alt: viz timeline :srcset: /auto_examples/10_animation/images/sphx_glr_viz_timeline_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.120 seconds) .. _sphx_glr_download_auto_examples_10_animation_viz_timeline.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_timeline.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_timeline.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_