beautypg.com

Random numbers methods (expression reference) – Adobe After Effects User Manual

Page 687

background image

length(vec)

length(point1, point2)

lookAt(fromPoint, atPoint)

To the top

Note:

seedRandom(offset, timeless=false)

random()

random(maxValOrArray)

random(minValOrArray, maxValOrArray)

Normalizes the vector so that its length is 1.0. Using the normalize method is a short way of performing the operation div(vec,

length(vec))

.

Return type: Number.

Argument type: vec is an Array.

Returns the length of vector vec.

Return type: Number.

Argument type: point1 and point2 are Arrays.

Returns the distance between two points. The point2 argument is optional. For example, length(point1, point2) is the same as

length(sub(point1, point2))

.

For example, add this expression to the Focus Distance property of a camera to lock the focal plane to the camera's point of interest so that the
point of interest is in focus:

length(position, pointOfInterest)

Return type: Array [3].

Argument type: fromPoint and atPoint are Arrays [3].

The argument fromPoint is the location in world space of the layer you want to orient. The argument atPoint is the point in world space you want to
point the layer at. The return value can be used as an expression for the Orientation property, making the z axis of the layer point at atPoint. This
method is especially useful for cameras and lights. If you use this expression on a camera, turn off auto-orientation. For example, this expression
on the Orientation property of a spot light makes the light point at the anchor point of layer number 1 in the same composition:

lookAt(position, thisComp.layer(1).position)

Random Numbers methods (expression reference)

The wiggle method—which is used to randomly vary a property value—is in the Property attributes and methods category. (See

Property

attributes and methods (expression reference)

.)

Return type: none.

Argument type: offset is a Number, timeless is a Boolean.

The random and gaussRandom methods use a seed value that controls the sequence of numbers. By default, the seed is computed as a function

of a unique layer identifier, the property within the layer, the current time, and an offset value of 0. Call seedRandom to set the offset to something

other than 0 to create a different random sequence.

Use true for the timeless argument to not use the current time as input to the random seed. Using true for the timeless argument allows you to

generate a random number that doesn’t vary depending on the time of evaluation.

The offset value, but not the timeless value, is also used to control the initial value of the wiggle function.

For example, this expression on the Opacity property sets the Opacity value to a random value that does not vary with time:

seedRandom(123456, true); random()*100

The multiplication by 100 in this example converts the value in the range 0–1 returned by the random method into a number in the range 0–100;

this range is more typically useful for the Opacity property, which has values from 0% to 100%.

Return type: Number.

Returns a random number in the range 0–1.

In After Effects CC and CS6, the behavior of random() is changed to be more random when layer ids are close together. The wiggle() expression
is not affected.

Return type: Number or Array.

Argument type: maxValOrArray is a Number or Array.

If maxValOrArray is a Number, this method returns a number in the range from 0 to maxValOrArray. If maxValOrArray is an Array, this method
returns an Array with the same dimension as maxValOrArray, with each component ranging from 0 to the corresponding component of
maxValOrArray.

Return type: Number or Array.

Argument type: minValOrArray and maxValOrArray are Numbers or Arrays.

683

This manual is related to the following products: