Ramp to Null expression

grad-1

These expressions will link the Start and End points of the Gradient Ramp effect to the position, rotation and scale of a null layer. Alternatively, you could use the first expression (slightly modified) to link the Start and End points to 2 separate null layers.

Create a new null layer and name it “RAMP DRIVER” for this example.

On a solid layer, apply the Gradient Ramp effect (in the Generate effects menu) and Option-Click (Win: Alt+Click) the Start of Ramp stopwatch to open the expression window.

// Apply to Start of Ramp
L = thisComp.layer("RAMP DRIVER");
pos = L.toComp(L.anchorPoint);
// Remove this last line if a text layer or constantly-rasterizing vector layer.
fromComp(pos);

The above expression is interpreted in Comp space, so the solid layer can be of any size, position and rotation and the gradient will still be referenced to the null layer.

The following expression uses the Rotation transform of the null layer to define the direction of the gradient, however this will not work as intended if the null layer is rotated via a parented layer transform.

// Apply to End of Ramp
L = thisComp.layer("RAMP DRIVER");
p1 = L.toComp(L.anchorPoint);
rot = degreesToRadians(L.transform.rotation);
amp = L.transform.scale[0];

x = Math.cos(rot) * amp;
y = Math.sin(rot) * amp;
pos = [x,y] + p1;
// Remove this last line if a text layer or constantly-rasterizing vector layer.
fromComp(pos);

Note: If you have applied the Gradient Ramp to a text layer or constantly-rasterized vector layer, you can remove the fromComp(pos) line from both expressions.

Leave a Reply