# Adjusting Particles Using Expressions

With the ParticleExpression node, you can adjust your particles by setting expressions on their attributes. Using expressions gives you a vast variety of ways of adjusting how your particles behave. You can use a similar expression syntax as you would elsewhere in Nuke, with the exception that some functions that work in normal Nuke expressions aren't available in particle expressions and vice versa.

The main difference between Nuke’s Expression node and ParticleExpression is that particle expressions can return a 3D vector instead of just a single floating point number. If a particle expression returns a single number N in a field that expects a vector (such as velocity or acceleration) it is converted into a vector with N for each of its components. For more information about the functions you can use with ParticleExpression, see Particle Expression Functions.

1. | Connect the ParticleExpression node to your particle stream. |

2. | In the ParticleExpression controls you can use four temporary expression fields. With these, you can set up any expression on a particle attribute and then give it a temporary name. This temporary name can then be used in the following fields to refer to the corresponding temporary expression. This can be useful if you need to use a long expression in several fields. By default, the per-particle box is ticked to make the expressions affect each particle individually. Uncheck the box to apply the expression to all particles at once. For more information on expressions, see Expressions. |

3. | You can also set expressions on a set of attribute fields: |

• color - set an expression to edit the color of the particles.

• opacity - set an expression to edit the opacity of the particles.

• size - set an expression to edit the size of the particles.

• mass - set an expression to edit the mass of the particles.

• accel - set an expression to edit the acceleration of the particles.

• force - set an expression to edit the force of the particles.

• pos - set an expression to edit the position of the particles. For example, enter sin (age * 10) * 5 to emit particles randomly on a single static line.

• vel - set an expression to edit the velocity of the particles.

• onlyonnew - check this next to each attribute field to make the expression only affect new particles and ignore any existing ones.

# Particle Expression Functions

Here are some functions you can use with the ParticleExpression node:

Function |
Purpose |
Related Functions |

abs(f) |
Returns the absolute value of f. |
See also: fabs. |

acos(f) |
Returns the arc cosine of f. The result is the angle in radians whose cosine is f. |
See also: cos, cosh, asin, atan2. |

age |
The age of the particle, in frames. |
- |

asin(f) |
Returns the arc sine of an angle. The result is the angle in radians whose sine is f. |
- |

atan(f) |
Returns the arc tangent of an angle. The result is the angle in radians whose tangent is f. Can be called with one or two arguments; if called with two arguments it's equivalent to atan2. |
- |

atan2(x,y) |
Returns the principal value of the arc tangent of y/x, using the signs of the two arguments to determine the quadrant of the result. |
See also: sin, cos, tan, asin, acos, atan, hypot. |

ceil(f) |
The ceiling of f, rounding any fractional part up. |
- |

color |
The color of the particle. This is a 3D vector value, where x() is the red component, y() is green and z() is blue. |
- |

cos(f) |
Returns the cosine of angle f. The angle is in radians. |
See also: sin, tan, asin, acos, atan, hypot. |

cosh(f) |
Returns the hyperbolic cosine of f. |
- |

exp(x) |
Returns the value of e (the base of natural logarithms) raised to the power of x. |
- |

fabs(f) |
A synonym for abs(f). |
- |

floor(f) |
The floor of a number, rounding any fractional part down. |
- |

fmod(x, y) |
Floating point modulus function. fmod(x, y) returns the remainder after dividing x by y. |
- |

hypot(x,y) |
The Euclidean distance function. hypot(x, y) returns the length of the hypotenuse of a right-angled triangle where the other sides have length x and y respectively. |
- |

id |
The index number for each particle. |
- |

int(f) |
Convert floating point number f to an integer, discarding any fractional part. |
See also: trunc(f). |

life |
The maximum lifetime of a particle, in frames. |
- |

log(x) |
Returns the natural logarithm of x. |
- |

log10(x) |
Returns the base 10 logarithm of x. |
- |

mag(v) |
Returns the magnitude (length) of the 3D vector v. |
- |

mass |
The mass of the particle. Used when applying a force to a particle. |
- |

new |
Returns 1 if the particle has just been created, 0 otherwise. |
- |

norm(v) |
Normalise the 3D vector v to have a length of 1.0 while pointing in the same direction. |
- |

opacity |
A number between 0.0 and 1.0, where 0.0 is fully transparent and 1.0 is fully opaque. |
- |

pos |
The position of the particle. This is a 3D vector. |
- |

pow(x, y) |
Returns x raised to the power of y. |
- |

pow2(f) |
Returns the square of f, i.e. f raised to the power of 2. |
- |

random |
Returns a random number. |
- |

randomv |
Returns a vector with each of the components between 0 and 1 (as per a volumetric cube). |
See also: uniformsamplesphere. |

rint(f) |
Round the floating point number f to an integer. |
- |

sin(f) |
Returns the sine of the angle f. The angle is in radians. |
- |

sinh(f) |
Returns the hyperbolic sine of f. |
- |

size |
The size of the particle. |
- |

sqrt(f) |
Returns the square root of f. f must be greater than or equal to zero. |
- |

tan(f) |
Returns the tangent of angle f. The angle is in radians. |
- |

tanh(f) |
Returns the hyperbolic tangent of f. |
- |

trunc(f) |
A synonym for int(f). |
- |

uniformsamplesphere |
Similar to randomv, but generates a true random unit vector. |
See also: randomv |

v(x, y,z) |
Create a vector from three separate numbers. |
- |

vel |
The velocity of the particle. This is a 3D vector. |
- |

x(v) |
Get the x component of the 3D vector v. |
- |

y(v) |
Get the y component of the 3D vector v. |
- |

z(v) |
Get the z component of the 3D vector v. |
- |