Example: Using Functions to Drive Animation
 
 
 

This example shows you how pre-established functions can be used as expressions to drive animation—see Expression Reference Tables.

The goal of this example is to create random noise using the Noise tool—see Noise Tool. You could create the appearance of random noise by modifying the Noise Seed attribute using periodic keyframes. However, a more simple approach is to use a random number function. In this case, the TrueRand function is used.

NoteIt is assumed that you currently have the Player, Schematic, and Composition Browser open. With the focus on Schematic, use Ctrl + N (Windows and Linux) or Cmd + N (Mac OS) to create a new composition.

To create random noise using a random number function:

  1. From the Tools tab, drag the Noise tool from the Image Generation folder to the dependency graph in the Schematic view and connect it to the Output node.

  2. In the Player controls, change the composition's total number of frames to 100.

  3. In the tool UI, set the Fill, Start, and End color preferences.

  4. Right-click the Noise Seed value field and select Set Expression from the menu.

    The Expresso Calculator appears along with a dashed green line at the top of the Noise Seed value field. This indicates that an expression is about to be applied, or has already been applied.

    (a)  Dashed green line appears  

  5. Select the Random button if it is not already selected.
  6. Select the TrueRand button.

    An empty expression appears in the text field.

    NoteIf you are familiar with the syntax of expressions, you can type them directly into the text field.

    As the TrueRand function description indicates (see Random Number Functions) the function returns a truly random value between two given numbers. Since the Noise Seed value can range from 0 to 1, it is suggested that these values be used as the range.

  7. Enter the value range of 0 to 1 between the brackets in the text field, making sure you separate the values with a comma.
  8. Play the composition.
NoteYou can view the expression in a graph view at any time by right-clicking the attribute's value field containing the expression, and then selecting Edit Expression from the menu. The Expresso Calculator appears. Select the Graph button to view the expression in a graph.

There are other expressions, and combinations of expressions that you can use to achieve the same results. For example, you can create random noise (with the Noise tool) by using the Rand function where the seed is calculated as time (t) multiplied (*) by the number of frames in the composition. Therefore, if the composition is 100 frames long, the expression would look like this:

Another expression that can be used to create random noise with the Noise tool is the Abs math function.

This expression indicates the Noise Seed is based on an absolute value (anything between 0 and 1) of the angle (in radians) of the sine wave created by the current time (t). It is then multiplied (*) by a frequency of 50. The expression would still be valid if the Abs math function were not part of the string.