.. 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 ` 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-22 .. code-block:: Python import numpy as np from fury import actor, window from fury.animation import Animation, Timeline from fury.animation.interpolator import spline_interpolator scene = window.Scene() showm = window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) .. GENERATED FROM PYTHON SOURCE LINES 23-25 Position keyframes as a dict object containing timestamps as keys and positions as values. .. GENERATED FROM PYTHON SOURCE LINES 25-34 .. 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 35-36 creating FURY dots to visualize the position values. .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python pos_dots = actor.dot(np.array(list(position_keyframes.values()))) .. GENERATED FROM PYTHON SOURCE LINES 39-41 creating two timelines (one uses linear and the other uses' spline interpolator), each timeline controls a sphere actor .. GENERATED FROM PYTHON SOURCE LINES 41-49 .. code-block:: Python sphere_linear = actor.sphere(np.array([[0, 0, 0]]), (1, 0.5, 0.2), 0.5) linear_anim = Animation() linear_anim.add_actor(sphere_linear) linear_anim.set_position_keyframes(position_keyframes) .. GENERATED FROM PYTHON SOURCE LINES 50-52 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 54-56 creating a second timeline that translates another larger sphere actor using spline interpolator. .. GENERATED FROM PYTHON SOURCE LINES 56-60 .. code-block:: Python sphere_spline = actor.sphere(np.array([[0, 0, 0]]), (0.3, 0.9, 0.6), 1) spline_anim = Animation(sphere_spline) spline_anim.set_position_keyframes(position_keyframes) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Setting 5th degree spline interpolator for position keyframes. .. GENERATED FROM PYTHON SOURCE LINES 62-64 .. code-block:: Python spline_anim.set_position_interpolator(spline_interpolator, degree=5) .. GENERATED FROM PYTHON SOURCE LINES 65-69 Wrapping animations up! ============================================================================= Adding everything to a ``Timeline`` to control the two timelines. .. GENERATED FROM PYTHON SOURCE LINES 71-72 First we create a timeline with a playback panel: .. GENERATED FROM PYTHON SOURCE LINES 72-74 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 75-76 Add visualization dots actor to the scene. .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: Python scene.add(pos_dots) .. GENERATED FROM PYTHON SOURCE LINES 79-80 Adding the animations to the timeline (so that it controls their playback). .. GENERATED FROM PYTHON SOURCE LINES 80-82 .. code-block:: Python timeline.add_animation([linear_anim, spline_anim]) .. GENERATED FROM PYTHON SOURCE LINES 83-84 Adding the timeline to the show manager. .. GENERATED FROM PYTHON SOURCE LINES 84-87 .. code-block:: Python showm.add_animation(timeline) .. GENERATED FROM PYTHON SOURCE LINES 88-90 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 90-98 .. code-block:: Python interactive = False if interactive: showm.start() window.record(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.216 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 ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_spline_interpolator.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_