.. 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 <sphx_glr_download_auto_examples_10_animation_viz_introduction.py>`
        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-68

.. code-block:: Python


    import numpy as np

    import fury

    scene = fury.window.Scene()

    showm = fury.window.ShowManager(scene=scene, size=(900, 768))
    showm.initialize()









.. GENERATED FROM PYTHON SOURCE LINES 69-75

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 75-77

.. code-block:: Python

    animation = fury.animation.Animation()








.. GENERATED FROM PYTHON SOURCE LINES 78-79

We also create the FURY sphere actor that will be animated.

.. GENERATED FROM PYTHON SOURCE LINES 79-81

.. code-block:: Python

    sphere = fury.actor.sphere(np.zeros([1, 3]), np.ones([1, 3]))








.. GENERATED FROM PYTHON SOURCE LINES 82-83

Then lets add the sphere actor to the ``Animation``

.. GENERATED FROM PYTHON SOURCE LINES 83-85

.. code-block:: Python

    animation.add_actor(actor=sphere)








.. GENERATED FROM PYTHON SOURCE LINES 86-90

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 90-95

.. 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 96-97

The ``Animation`` must be added to the ``ShowManager`` as follows:

.. GENERATED FROM PYTHON SOURCE LINES 97-100

.. code-block:: Python

    showm.add_animation(animation)
    scene.camera().SetPosition(0, 0, 10)








.. GENERATED FROM PYTHON SOURCE LINES 101-103

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 106-108

No need to add the sphere actor to scene, since it's now a part of the
``Animation``.

.. GENERATED FROM PYTHON SOURCE LINES 108-117

.. code-block:: Python


    interactive = False

    if interactive:
        showm.start()

    fury.window.record(
        scene=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.122 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 <viz_introduction.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: viz_introduction.py <viz_introduction.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_