.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_color_interpolators.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_color_interpolators.py: ============================ Keyframe Color Interpolators ============================ Color animation explained in this tutorial and how to use different color space interpolators. .. GENERATED FROM PYTHON SOURCE LINES 9-30 .. code-block:: Python import numpy as np from fury import actor, window from fury.animation import Animation from fury.animation.interpolator import ( hsv_color_interpolator, lab_color_interpolator, step_interpolator, xyz_color_interpolator, ) from fury.animation.timeline import Timeline from fury.colormap import distinguishable_colormap scene = window.Scene() showm = window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) .. GENERATED FROM PYTHON SOURCE LINES 31-32 Initializing positions of the cubes that will be color-animated. .. GENERATED FROM PYTHON SOURCE LINES 32-42 .. code-block:: Python cubes_pos = np.array( [ [[-2, 0, 0]], [[0, 0, 0]], [[2, 0, 0]], [[4, 0, 0]], [[6, 0, 0]], ] ) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Static labels for different interpolators (for show) .. GENERATED FROM PYTHON SOURCE LINES 44-51 .. code-block:: Python linear_text = actor.vector_text('Linear', (-2.64, -1, 0)) lab_text = actor.vector_text('LAB', (-0.37, -1, 0)) hsv_text = actor.vector_text('HSV', (1.68, -1, 0)) xyz_text = actor.vector_text('XYZ', (3.6, -1, 0)) step_text = actor.vector_text('Step', (5.7, -1, 0)) scene.add(step_text, lab_text, linear_text, hsv_text, xyz_text) .. GENERATED FROM PYTHON SOURCE LINES 52-56 Creating an animation to animate the actor. Also cube actor is provided for each timeline to handle as follows: ``Animation(actor)``, ``Animation(list_of_actors)``, or actors can be added later using ``animation.add()`` or ``animation.add_actor()`` .. GENERATED FROM PYTHON SOURCE LINES 56-62 .. code-block:: Python anim_linear_color = Animation(actor.cube(cubes_pos[0])) anim_LAB_color = Animation(actor.cube(cubes_pos[1])) anim_HSV_color = Animation(actor.cube(cubes_pos[2])) anim_XYZ_color = Animation(actor.cube(cubes_pos[3])) anim_step_color = Animation(actor.cube(cubes_pos[4])) .. GENERATED FROM PYTHON SOURCE LINES 63-65 Creating a timeline to control all the animations (one for each color interpolation method) .. GENERATED FROM PYTHON SOURCE LINES 65-68 .. code-block:: Python timeline = Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 69-70 Adding animations to a Timeline. .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: Python timeline.add_animation( [anim_linear_color, anim_LAB_color, anim_HSV_color, anim_XYZ_color, anim_step_color] ) .. GENERATED FROM PYTHON SOURCE LINES 75-79 Setting color keyframes ======================= Setting the same color keyframes to all the animations .. GENERATED FROM PYTHON SOURCE LINES 81-82 First, we generate some distinguishable colors .. GENERATED FROM PYTHON SOURCE LINES 82-84 .. code-block:: Python colors = distinguishable_colormap(nb_colors=4) .. GENERATED FROM PYTHON SOURCE LINES 85-86 Then, we set them as keyframes for the animations .. GENERATED FROM PYTHON SOURCE LINES 86-94 .. code-block:: Python for t in range(0, 20, 5): col = colors.pop() anim_linear_color.set_color(t, col) anim_LAB_color.set_color(t, col) anim_HSV_color.set_color(t, col) anim_XYZ_color.set_color(t, col) anim_step_color.set_color(t, col) .. GENERATED FROM PYTHON SOURCE LINES 95-97 Changing the default scale interpolator to be a step interpolator The default is linear interpolator for color keyframes .. GENERATED FROM PYTHON SOURCE LINES 97-102 .. code-block:: Python anim_HSV_color.set_color_interpolator(hsv_color_interpolator) anim_LAB_color.set_color_interpolator(lab_color_interpolator) anim_step_color.set_color_interpolator(step_interpolator) anim_XYZ_color.set_color_interpolator(xyz_color_interpolator) .. GENERATED FROM PYTHON SOURCE LINES 103-104 Adding the main timeline to the show manager .. GENERATED FROM PYTHON SOURCE LINES 104-112 .. code-block:: Python showm.add_animation(timeline) interactive = False if interactive: showm.start() window.record(scene, out_path='viz_keyframe_animation_colors.png', size=(900, 768)) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_color_interpolators_001.png :alt: viz color interpolators :srcset: /auto_examples/10_animation/images/sphx_glr_viz_color_interpolators_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.109 seconds) .. _sphx_glr_download_auto_examples_10_animation_viz_color_interpolators.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_color_interpolators.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_color_interpolators.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_