Skip to main content

JavaScript Emitter

Experimental Feature

This is an experimental feature. To enable, check Enable Experimental Features in Preferences. Experimental features are only available as part of a Professional licence.

Intro

Use JavaScript to create a custom Particle Emitter.

For more information on how JavaScript can be used across all JavaScript Layers see JavaScript Layers.

See JavaScript Layers

Global Variables

time - The frame number.

fps - The Frame Rate of the Composition.

lifespan - The Lifespan of the Particles.

particles - The array of Particles.

Data objects can be saved or loaded in the same way as any other JavaScript Layers.

UI

Common Attributes +

Custom Color - A representation of the Emitter is drawn in the Viewport – when Custom Color is checked it will been drawn using the value set in Color. When unchecked the Label Color is used (this is the color used for the row in the Scene Window).

Color - Set a Custom Color for the Emitter's Viewport draw.

Time - This attribute is connected to the Composition's Time to animate the Particles on each frame. The connection can be replaced with keyframes or another Behaviour if required.

FPS - This attribute is connected to the Composition's Frame Rate. The connection can be removed and entered manually.

Expression Window - Enter a JavaScript expression here.

tip
  1. Create a Particle Shape.
  2. In the Attribute Editor, click the + button on the Emitters Attribute and choose JavaScript Emitter.
  3. Press Play.
// The default JavaScript Emitter expression.
// Emit for one second every other second while rotating.
var seconds = Math.floor(time / fps);
if (seconds % 2 == 0) {
for (let i = 0; i < 5; i++) {
var particle = {};
particle.position = {'x': 0, 'y': 0};
particle.speed = 10;
particle.angle = (time*10)+cavalry.random(-15, 15, time, i);

particles.push(particle);
}
}