.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_introduction.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_introduction.py: =============================== Keyframe animation introduction =============================== This tutorial explains keyframe animation in FURY. .. GENERATED FROM PYTHON SOURCE LINES 9-17 Animations in FURY ================== FURY provides an easy-to-use animation system that enables users creating complex animations based on keyframes. The user only need to provide the attributes of actors at certain times (keyframes), and the system will take care of animating everything through interpolating between those keyframes. .. GENERATED FROM PYTHON SOURCE LINES 20-27 What exactly is a keyframe ========================== A Keyframe is simply a marker of time which stores the value of a property. A keyframe consists of a timestamp and some data. These data can be anything such as temperature, position, or scale. .. GENERATED FROM PYTHON SOURCE LINES 29-57 What is Keyframe Animation ========================== Keyframe animations is a technique to simplify the process of animating a scene. Instead of providing the actor attributes for each frame, only a small amount of keyframes are needed to create a smooth animation. Each keyframe encodes the state of an actor at a certain timestamp. For instance a keyframe might define that an actor should be positioned at the origin (0,0,0) at the start of the animation. Another keyframe may define that the actor should move to position (1,0,0) after 10 seconds. The system will take care of interpolating the position of that actor between these two keyframes. Almost any parameter that you can set for FURY actors can be animated using keyframes. For example, a Keyframe might define that the position of a FURY actor is (0, 0, 0) at time equals 1 second. The goal of a Keyframe is to allow for interpolated animation, meaning, for example, that the user could then add another key at time equals 3 seconds, specifying the actor's position is (1, 1, 0), Then the correct position of the actor for all the times between 3 and 10 will be interpolated. For this tutorial, we are going to use the FURY animation module to translate FURY sphere actor. .. GENERATED FROM PYTHON SOURCE LINES 57-70 .. code-block:: Python import numpy as np from fury import actor, window from fury.animation import Animation scene = window.Scene() showm = window.ShowManager(scene, size=(900, 768)) showm.initialize() .. GENERATED FROM PYTHON SOURCE LINES 71-77 Translating a sphere ==================== This is a quick demo showing how to translate a sphere from (0, 0, 0) to (1, 1, 1). First, we create an ``Animation``. See ``viz_interpolators.py`` tutorial .. GENERATED FROM PYTHON SOURCE LINES 77-79 .. code-block:: Python animation = Animation() .. GENERATED FROM PYTHON SOURCE LINES 80-81 We also create the FURY sphere actor that will be animated. .. GENERATED FROM PYTHON SOURCE LINES 81-83 .. code-block:: Python sphere = actor.sphere(np.zeros([1, 3]), np.ones([1, 3])) .. GENERATED FROM PYTHON SOURCE LINES 84-85 Then lets add the sphere actor to the ``Animation`` .. GENERATED FROM PYTHON SOURCE LINES 85-87 .. code-block:: Python animation.add_actor(sphere) .. GENERATED FROM PYTHON SOURCE LINES 88-92 Then, we set our position keyframes at different timestamps Here we want the sphere's position at the beginning to be [0, 0, 0]. And then at time equals 3 seconds to be at [1, 1, 0] then finally at the end (time equals 6) to return to the initial position which is [0, 0, 0] again. .. GENERATED FROM PYTHON SOURCE LINES 92-97 .. code-block:: Python animation.set_position(0.0, [-1, -1, 0]) animation.set_position(3.0, [1, 1, 0]) animation.set_position(6.0, [-1, -1, 0]) .. GENERATED FROM PYTHON SOURCE LINES 98-99 The ``Animation`` must be added to the ``ShowManager`` as follows: .. GENERATED FROM PYTHON SOURCE LINES 99-102 .. code-block:: Python showm.add_animation(animation) scene.camera().SetPosition(0, 0, 10) .. GENERATED FROM PYTHON SOURCE LINES 103-105 Animation can be added to the scene instead of the ``ShowManager`` but, the animation will need to be updated and then render the scene manually. .. GENERATED FROM PYTHON SOURCE LINES 108-110 No need to add the sphere actor to scene, since it's now a part of the ``Animation``. .. GENERATED FROM PYTHON SOURCE LINES 110-119 .. code-block:: Python interactive = False if interactive: showm.start() window.record( scene, out_path='viz_keyframe_animation_introduction.png', size=(900, 768) ) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_introduction_001.png :alt: viz introduction :srcset: /auto_examples/10_animation/images/sphx_glr_viz_introduction_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_introduction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_introduction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_introduction.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_