.. 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-24 .. 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 ) cube = fury.actor.cube( np.array([[0, 0, 0]]), directions=(0, 0, 0), colors=(1, 0, 1), scales=6 ) .. GENERATED FROM PYTHON SOURCE LINES 25-26 Creating an ``Animation`` to animate the actor and show its motion path. .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python anim = fury.animation.Animation(length=2 * np.pi, loop=True, motion_path_res=200) .. GENERATED FROM PYTHON SOURCE LINES 29-31 Adding the sphere actor to the timeline This could've been done during initialization. .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python anim.add_actor(cube) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Creating time dependent functions. .. GENERATED FROM PYTHON SOURCE LINES 36-58 .. 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 59-62 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 62-67 .. 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 68-69 changing camera position to observe the animation better. .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: Python scene.set_camera(position=(0, 0, 90)) .. GENERATED FROM PYTHON SOURCE LINES 72-73 Adding the animation to the show manager. .. GENERATED FROM PYTHON SOURCE LINES 73-84 .. code-block:: Python showm.add_animation(anim) interactive = False if interactive: showm.start() fury.window.record( scene=scene, out_path="viz_keyframe_animation_evaluators.png", size=(900, 768) ) .. _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 ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_using_time_equations.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_