Keyframe Color Interpolators#

Color animation explained in this tutorial and how to use different color space interpolators.

import numpy as np
from fury import actor, window
from fury.animation import Animation
from fury.animation.timeline import Timeline
from fury.animation.interpolator import step_interpolator, \
    lab_color_interpolator, hsv_color_interpolator, xyz_color_interpolator
from fury.colormap import distinguishable_colormap

scene = window.Scene()

showm = window.ShowManager(scene,
                           size=(900, 768), reset_camera=False,

Initializing positions of the cubes that will be color-animated.

cubes_pos = np.array([
    [[-2, 0, 0]],
    [[0, 0, 0]],
    [[2, 0, 0]],
    [[4, 0, 0]],
    [[6, 0, 0]],

Static labels for different interpolators (for show)

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)

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()

Creating a timeline to control all the animations (one for each color interpolation method)

timeline = Timeline(playback_panel=True)

Adding animations to a Timeline.

Setting color keyframes#

Setting the same color keyframes to all the animations

First, we generate some distinguishable colors

Then, we set them as keyframes for the animations

Changing the default scale interpolator to be a step interpolator The default is linear interpolator for color keyframes

Adding the main timeline to the show manager


interactive = False

if interactive:

window.record(scene, out_path='viz_keyframe_animation_colors.png',
              size=(900, 768))
viz color interpolators

Total running time of the script: ( 0 minutes 0.093 seconds)

Gallery generated by Sphinx-Gallery