.. 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-24 .. code-block:: Python import numpy as np from fury import actor, window from fury.animation import Animation, Timeline .. GENERATED FROM PYTHON SOURCE LINES 25-26 We create our ``Scene`` and ``ShowManager`` as usual. .. GENERATED FROM PYTHON SOURCE LINES 26-31 .. code-block:: Python scene = window.Scene() showm = window.ShowManager(scene, size=(900, 768)) showm.initialize() .. GENERATED FROM PYTHON SOURCE LINES 32-37 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 39-40 Creating a ``Timeline`` with a PlaybackPanel. .. GENERATED FROM PYTHON SOURCE LINES 40-42 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Creating a Fury Animation as usual .. GENERATED FROM PYTHON SOURCE LINES 44-51 .. 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 52-60 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 60-62 .. code-block:: Python anim.set_position(0.0, np.array([1, 2, 3])) .. GENERATED FROM PYTHON SOURCE LINES 63-67 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 67-71 .. 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 72-73 That's it! Now we are done setting keyframes. .. GENERATED FROM PYTHON SOURCE LINES 75-77 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 77-79 .. code-block:: Python timeline.add_animation(anim) .. GENERATED FROM PYTHON SOURCE LINES 80-82 Now we add only the ``Timeline`` to the ``ShowManager`` the same way we add ``Animation`` to the ``ShowManager``. .. GENERATED FROM PYTHON SOURCE LINES 82-92 .. 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)) .. _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 `_