Pinecoast Software Inc.
      Home
Subscribe
 

Tutorial: Color Interpolator

The Color Interpolator Node

Color Interpolator

A ColorInterpolator node will be used to change to color of the top cube. In preparation for this, the Material node of this cube will be given the name MyMaterial. A TimeSensor node called TS will be added to the scene to drive the animation. Its cycleInterval will be set to 5 seconds and the loop field will be set to TRUE so that the animation repeats indefinitely. Part of the code for this file is shown below.



 


Transform {
  translation 0 4 0
  children
    Shape {
      appearance Appearance {
        material DEF MyMaterial Material {
        }
      }
      geometry Box {
      }
    }
}
DEF TS TimeSensor {
  cycleInterval 5
  loop TRUE
}

 

Now a ColorInterpolator node called CI is added to the scene. It has four keys, and the color values corresponding to these keys are blue, yellow, red and red, given in RGB format with individual values between 0 and 1.

 


DEF CI ColorInterpolator {
  key [ 0, 0.333333, 0.666667, 1 ]
  keyValue [ 0 0 1, 1 1 0, 1 0 0, 1 0 0 ]
}

 

To make the animation work two ROUTE statements are added to the scene. As time passes the TimeSensor TS sends out fraction_changed events indicating the fraction of the current 5 second cycle. When the ColorInterpolator node CI receives a set_fraction event, it calculates the corresponding color value and sends it to the diffuseColor field of the Material node MyMaterial, changing the color of the cube. Because the cycle is 5 seconds in duration, the color value from 0 to 1.66 seconds changes from blue to yellow. From 1.66 to 3.33 seconds, the fraction value will increase from 0.33 to 0.66, and the color will change frm yellow to red. From 3.33 to 5 seconds, the color will remain red. After 5 seconds a new cycle will start and the colors will repeat.

 


ROUTE TS.fraction_changed TO CI.set_fraction
ROUTE CI.value_changed TO MyMaterial.diffuseColor

 

Color Interpolator Dialog

In SwirlX3D the ColorInterpolator node can be edited directly, or the illustrated Edit Dialog can be used. The dialog has two panels. The first panel is for entering and editing the keys and colors. The second panel is used to adjust the spacing of the keys. For example, the keys within a specified subinterval can be scaled or spaced evenly.



Download tutorial files





Copyright © Pinecoast Software 2000-2008. All rights reserved.