.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_spline_interpolator.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_auto_examples_10_animation_viz_spline_interpolator.py>` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_animation_viz_spline_interpolator.py: ============================= Keyframes Spline Interpolator ============================= Tutorial on making keyframe-based animation in FURY using Spline interpolators. .. GENERATED FROM PYTHON SOURCE LINES 8-20 .. code-block:: Python import numpy as np import fury scene = fury.window.Scene() showm = fury.window.ShowManager( scene=scene, size=(900, 768), reset_camera=False, order_transparent=True ) .. GENERATED FROM PYTHON SOURCE LINES 21-23 Position keyframes as a dict object containing timestamps as keys and positions as values. .. GENERATED FROM PYTHON SOURCE LINES 23-32 .. code-block:: Python position_keyframes = { 0.0: np.array([0, 0, 0]), 2.0: np.array([10, 3, 5]), 4.0: np.array([20, 14, 13]), 6.0: np.array([-20, 20, 0]), 8.0: np.array([17, -10, 15]), 10.0: np.array([0, -6, 0]), } .. GENERATED FROM PYTHON SOURCE LINES 33-34 creating FURY dots to visualize the position values. .. GENERATED FROM PYTHON SOURCE LINES 34-36 .. code-block:: Python pos_dots = fury.actor.dot(np.array(list(position_keyframes.values()))) .. GENERATED FROM PYTHON SOURCE LINES 37-39 creating two timelines (one uses linear and the other uses' spline interpolator), each timeline controls a sphere actor .. GENERATED FROM PYTHON SOURCE LINES 39-47 .. code-block:: Python sphere_linear = fury.actor.sphere(np.array([[0, 0, 0]]), (1, 0.5, 0.2), radii=0.5) linear_anim = fury.animation.Animation() linear_anim.add_actor(sphere_linear) linear_anim.set_position_keyframes(position_keyframes) .. GENERATED FROM PYTHON SOURCE LINES 48-50 Note: linear_interpolator is used by default. So, no need to set it for this first animation that we need to linearly interpolate positional animation. .. GENERATED FROM PYTHON SOURCE LINES 52-54 creating a second timeline that translates another larger sphere actor using spline interpolator. .. GENERATED FROM PYTHON SOURCE LINES 54-58 .. code-block:: Python sphere_spline = fury.actor.sphere(np.array([[0, 0, 0]]), (0.3, 0.9, 0.6), radii=1) spline_anim = fury.animation.Animation(actors=sphere_spline) spline_anim.set_position_keyframes(position_keyframes) .. GENERATED FROM PYTHON SOURCE LINES 59-60 Setting 5th degree spline interpolator for position keyframes. .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python spline_anim.set_position_interpolator(fury.animation.spline_interpolator, degree=5) .. GENERATED FROM PYTHON SOURCE LINES 63-67 Wrapping animations up! ============================================================================= Adding everything to a ``Timeline`` to control the two timelines. .. GENERATED FROM PYTHON SOURCE LINES 69-70 First we create a timeline with a playback panel: .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python timeline = fury.animation.Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 73-74 Add visualization dots actor to the scene. .. GENERATED FROM PYTHON SOURCE LINES 74-76 .. code-block:: Python scene.add(pos_dots) .. GENERATED FROM PYTHON SOURCE LINES 77-78 Adding the animations to the timeline (so that it controls their playback). .. GENERATED FROM PYTHON SOURCE LINES 78-80 .. code-block:: Python timeline.add_animation([linear_anim, spline_anim]) .. GENERATED FROM PYTHON SOURCE LINES 81-82 Adding the timeline to the show manager. .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: Python showm.add_animation(timeline) .. GENERATED FROM PYTHON SOURCE LINES 86-88 Now that these two animations are added to timeline, if the timeline is played, paused, ..., all these changes will reflect on the animations. .. GENERATED FROM PYTHON SOURCE LINES 88-98 .. code-block:: Python interactive = False if interactive: showm.start() fury.window.record( scene=scene, out_path="viz_keyframe_animation_spline.png", size=(900, 768) ) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_spline_interpolator_001.png :alt: viz spline interpolator :srcset: /auto_examples/10_animation/images/sphx_glr_viz_spline_interpolator_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.114 seconds) .. _sphx_glr_download_auto_examples_10_animation_viz_spline_interpolator.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_spline_interpolator.ipynb <viz_spline_interpolator.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_spline_interpolator.py <viz_spline_interpolator.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_