Modifying runtime expressions
 
 
 

You might have trouble seeing the color of a particle in any instant because the color changes so quickly. You can slow the change of colors to create a flashing Christmas light effect. The following steps make the particles change colors every second of animation.

To adjust the timing of the change of color

  1. Change the runtime expression to this:
    if ((frame % 24) == 0)
    	BubblesShape.rgbPP = sphrand(1);
    

    This expression uses the modulus operator (%) to control when the RGB PP attribute of the particles receives a random color. The modulus operator returns the remainder after division. For example, 24 divided by 24 returns 0, but 25 divided by 24 returns 1. (Dividing 25 by 24 equals 1 with a remainder of 1.)

    If the value of frame divided by 24 is equal to any number with a remainder of 0, the assignment to BubblesShape.rgbPP occurs. In other words, the assignment occurs when frame equals 24, 48, 72, and so on. At an animation rate of 24 frames/second, the assignment happens once each second.

    The == symbols mean is equal to. In conditional statements, be careful to type == rather than =. The = symbol means assign the value to.

  2. Rewind and play the animation again.

    When you go to the start time, the particles turn red because the creation expression executes. When the animation plays, the particles receive a random color once each second.

    Note that you can change the beginning red color to random colors by changing the creation expression to this:

    BubblesShape.rgbPP = sphrand(1);
    

    This is the same expression as the runtime expression.

  3. Save the scene if you plan to examine it later. This concludes the lesson.