.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_using_time_equations.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_using_time_equations.py: ===================== Keyframe animation ===================== Tutorial on making keyframe-based animation in FURY using custom functions. .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. 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), reset_camera=False, order_transparent=True ) cube = actor.cube(np.array([[0, 0, 0]]), (0, 0, 0), (1, 0, 1), scales=6) .. GENERATED FROM PYTHON SOURCE LINES 23-24 Creating an ``Animation`` to animate the actor and show its motion path. .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python anim = Animation(length=2 * np.pi, loop=True, motion_path_res=200) .. GENERATED FROM PYTHON SOURCE LINES 27-29 Adding the sphere actor to the timeline This could've been done during initialization. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python anim.add_actor(cube) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Creating time dependent functions. .. GENERATED FROM PYTHON SOURCE LINES 34-56 .. code-block:: Python def pos_eval(t): return np.array([np.sin(t), np.cos(t) * np.sin(t), 0]) * 15 def color_eval(t): return ( np.array([np.sin(t), np.sin(t - 2 * np.pi / 3), np.sin(t + np.pi / 3)]) + np.ones(3) ) / 2 def rotation_eval(t): return np.array([np.sin(t) * 360, np.cos(t) * 360, 0]) def scale_eval(t): return ( np.array([np.sin(t), np.sin(t - 2 * np.pi / 3), np.sin(t + np.pi / 3)]) + np.ones(3) * 2 ) / 5 .. GENERATED FROM PYTHON SOURCE LINES 57-60 Setting evaluator functions is the same as setting interpolators, but with one extra argument: `is_evaluator=True` since these functions does not need keyframes as input. .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: Python anim.set_position_interpolator(pos_eval, is_evaluator=True) anim.set_rotation_interpolator(rotation_eval, is_evaluator=True) anim.set_color_interpolator(color_eval, is_evaluator=True) anim.set_interpolator('scale', scale_eval, is_evaluator=True) .. GENERATED FROM PYTHON SOURCE LINES 66-67 changing camera position to observe the animation better. .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python scene.set_camera(position=(0, 0, 90)) .. GENERATED FROM PYTHON SOURCE LINES 70-71 Adding the animation to the show manager. .. GENERATED FROM PYTHON SOURCE LINES 71-80 .. code-block:: Python showm.add_animation(anim) interactive = False if interactive: showm.start() window.record(scene, out_path='viz_keyframe_animation_evaluators.png', size=(900, 768)) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_using_time_equations_001.png :alt: viz using time equations :srcset: /auto_examples/10_animation/images/sphx_glr_viz_using_time_equations_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_using_time_equations.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_using_time_equations.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_using_time_equations.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_