There is one other type of expression you can create for a particle object (shape node)—a runtime expression. By default, a runtime expression executes each frame during playback. A runtime expression does not execute when you go to the start time (or at the time in which a particle is emitted).
You’ll often create both types of expressions for a particle object—a creation expression that initializes an attribute value in the first frame, and a runtime expression that controls the attribute value in subsequent frames.
The following steps show how to create a runtime expression to change particle color during playback.
To create a runtime expression
BubblesShape.rgbPP = sphrand(1);
The particles flicker in random colors as the animation plays back. The runtime expression controls the rgbPP attribute during playback. Because rgbPP is a per particle attribute, the runtime expression executes for each particle in the object for each frame. For each particle, the expression assigns the rgbPP attribute the output from the execution of the sphrand function with an argument of 1. The sphrand function is one of Maya’s many built-in mathematical functions that are useful in expressions.
The sphrand function with an argument of 1 assigns each particle’s rgbPP color a random vector. The vector represents a random point in a spherical region of radius 1. The left, middle, and right rgbPP color components get a value no less than -1 and no greater than 1. (R, G, and B values less than 0 are treated as 0—a black color).
The sphrand function returns a different random vector each execution, so each particle receives a different random rgbPP value, and therefore, a different color. The color changes each frame.
The particles become red when you go to the start time, and random colors during playback.