AE(After Effects) Expressions and Scripts
1.16K subscribers
3 photos
15 videos
14 files
8 links
Usefull expression and scripts for AE (After Effects). Automate your routine, speed up motion design process with the power of coding.
Download Telegram
This media is not supported in your browser
VIEW IN TELEGRAM
Blinking expression💡
Apply to Opacity

blinkRate = 20;
n=Math.sin(time*blinkRate);
if(n<0) 0; else 100;
This media is not supported in your browser
VIEW IN TELEGRAM
Range Mapper ↔️

Change the default slider control min and max values to your custom numbers.

input = effect("Slider Control")("Slider");

inputLow = 0; // default min value
inputHigh = 100; // default max value
outputLow = 466; // new min value
outputHigh = 618; // new max value

linear(input,inputLow,inputHigh,outputLow,outputHigh)


You can learn more about linear expression from this tutorial:
https://www.youtube.com/watch?v=2h9ZfUHVG6Q
👍2
⌨️Type On Effect Text Animation
Based on letter index

Apply to Source text

//Slider Name: Text
//Checkbox Name: On/Off

var sign = "|"; // change the blinking sign to "▌"or "_"
var blinkInterval = 15; // edit the blinking interval in frames
// slider with text length
var i = effect("Text")("ADBE Slider Control-0001");
// checkbox to turn the cursor on and off
var on = effect("On/Off")("ADBE Checkbox Control-0001");

var frames = timeToFrames(time);

var check = frames / blinkInterval;

if (on == 1) {
if (i.valueAtTime(time + thisComp.frameDuration) > i) {
end = sign;
} else {
if (Math.floor(check) % 2 == 0) {
end = sign;
} else {
end = " ";
}
}
} else {
end = " ";
}

text.sourceText.substr(0,parseInt(i)) + end;

https://www.youtube.com/watch?v=U6HxvLm-ADA&t=429s
This media is not supported in your browser
VIEW IN TELEGRAM
SourceRectAtTime() + Scale

By the default SourceRectAtTime()do not include Scale property so here is the script that include Scale factor.

width = thisComp.layer("blue").sourceRectAtTime().width;
height = thisComp.layer("blue").sourceRectAtTime().height;
thisScalePercentage = thisComp.layer("blue").transform.scale[0] / 100;
widthScale = width * thisScalePercentage;
heightScale = height * thisScalePercentage;
[widthScale, widthScale]
This media is not supported in your browser
VIEW IN TELEGRAM
Here is a quick tip to lock the object to the center of composition.

Position property:
[thisComp.width/2, thisComp.height/2]

Anchor point:
a = thisLayer.sourceRectAtTime(); height = a.height; width = a.width; top = a.top; left = a.left; x = left + width/2; y = top + height/2; [x,y];
1
This media is not supported in your browser
VIEW IN TELEGRAM
Image content fill into mask shape layer

Apply to Scale property

let mask = thisComp.layer("mask");
let imgWidth = thisLayer.sourceRectAtTime().width;
let imgHeight = thisLayer.sourceRectAtTime().height;
let maskScaleX = mask.transform.scale[0] / 100;
let maskScaleY = mask.transform.scale[1] / 100;
let maskWidth = mask.sourceRectAtTime().width * maskScaleX;
let maskHeight = mask.sourceRectAtTime().height * maskScaleY;
let scaleToX = maskWidth / imgWidth * 100;
let scaleToY = maskHeight / imgHeight * 100;
if (scaleToX >= scaleToY) {
scale = scaleToX;
} else if (scaleToY > scaleToX) {
scale = scaleToY;
} [scale, scale]
2👍2
This media is not supported in your browser
VIEW IN TELEGRAM
Parallax animation
The easy to use and customize parallax animation for multiply object. You just need to animate null (or other layer) position, then apply the multiply index value with slider contol for each layer.

Apply to position property:

let nullRefer = thisComp.layer("Null 1");
let multyplyerSlider = effect("index")("Slider");
let xReffer = nullRefer.transform.position[0] * multyplyerSlider;
let yReffer = nullRefer.transform.position[1] * multyplyerSlider;
let thisX = transform.position.value[0];
let thisY = transform.position.value[1];
x = thisX + xReffer;
y = thisY + yReffer;
[x, y]
👍1
This media is not supported in your browser
VIEW IN TELEGRAM
Custom variables based animation 🤔

I want to show you very specific trick witch allow you to animate object position of the layer with changeable size. It's allow you to animate objects based on variable(like Width, Height etc.) you have set inside expression and multiply by keyframe values that you set on the timeline. In this example below the keyframe values are set to -1, 0, 1. The position of the text animate from left side to center and right side does not matter what the length of the text.

let xValue = value[0];
let yValue = value[1];
let xCenter = thisComp.width / 2; let yCenter = thisComp.height / 2;
let layerWidth = thisLayer.sourceRectAtTime().width;
let layerHeight = thisLayer.sourceRectAtTime().height;
let thisScalePercentage = transform.scale[0]/100;
let widthScale = layerWidth * thisScalePercentage;
let heightScale = layerHeight * thisScalePercentage;
x = (xValue * (thisComp.width + widthScale) / 2) + xCenter;
y = (yValue * (thisComp.height + heightScale) / 2) + yCenter;
[x , yCenter]
This media is not supported in your browser
VIEW IN TELEGRAM
Repeater Text animation

1. Create Control layer. With slider control zRotation.

2. Create text layer "Original" that will be main refferance text. Make the text 3D layer

3. Copy text layer tha will reffer to layer "Original". Apply this expression to reffer to the text styles and source text:

var sourceTextProperty = thisComp.layer("Original").text.sourceText; var newStyle = sourceTextProperty.getStyleAt(0,time); newStyle.setText(sourceTextProperty);

4. Apply to the position property:

let x = thisComp.layer("Original").transform.position[0]; let y = thisComp.layer("Original").transform.position[1]; let z = -index-2; [x, y, z]

5. Apply to Orientation property:

let thisIndex = index-2; let zRotation = thisComp.layer("Control").effect("zRotation")("Slider"); let refferZ = thisComp.layer("Original").transform.zRotation; let z = refferZ + thisIndex * zRotation; [0, 0, z]

6. Dublicate layer with the expression as many times as you need.
Animate with slider control zRotation.
👍21
Spiral matrix layer duplicates based on layer index🌀



var user_id = index;
let margin = 0; //margin
function get_coordinates_from_user_id() {
var k = Math.ceil((Math.sqrt(user_id) - 1) / 2);
var t = 2 * k + 1;
var m = t * t;
t = t - 1;
if (user_id >= m - t) {
return [-k, k - (m - user_id)]
} else m = m - t;
if (user_id >= m - t) {
return [-k + (m - user_id), -k]
} else m = m - t;
if (user_id >= m - t) {
return [k, -k + (m - user_id)]
};
return [k - (m - user_id - t), k];
}
get_coordinates_from_user_id(user_id);
let sIndex = get_coordinates_from_user_id(user_id);
let width = thisLayer.sourceRectAtTime().width + margin;
let height = thisLayer.sourceRectAtTime().height + margin;
let thisScalePercentage = thisLayer.transform.scale[0] / 100;
let widthScale = width * thisScalePercentage * sIndex[0];
let heightScale = height * thisScalePercentage * sIndex[1];
[widthScale + value[0], heightScale + value[1]]
This media is not supported in your browser
VIEW IN TELEGRAM
Quick tip to debug your expression😱

Simply drag and drop property into comp window and AE automaticly create text layer witch shows you the current property value.
This media is not supported in your browser
VIEW IN TELEGRAM
Fit (Scale) one layer to another layer Width. and Height

Apply to Scale

targetL = thisComp.layer("Reffer Layer");
sourceW = sourceRectAtTime().width;
sourceH = sourceRectAtTime().height;
targetScW = targetL.transform.scale[0] / 100;
targetScH = targetL.transform.scale[1] / 100;
targetW = targetL.sourceRectAtTime().width * targetScW;
targetH = targetL.sourceRectAtTime().height * targetScH;
percentW = (targetW / sourceW * 100);
percentH = (targetH / sourceH * 100);
[percentW, percentH]
2