
Fun JavaScript for After Effects
I love writing JavaScript in After Effects. You get to instantly see the results!
Fun JavaScript for After Effects
I love writing JavaScript in After Effects. You get to instantly see the results!
Sine Animations
Your basic oscillating wave form. It's fun to make a predictable animation for things like clocks, or HUD images. You can also use them to draw fun lines and graphs.
// SINE ---------------
y = position[1];
x = position[0];
freq = 1;
amp = 100;
sin = amp * Math.sin(freq * time * Math.PI);
[x, y + sin]
// SINE CLIPPED ---------------
y = position[1];
x = position[0];
freq = 1;
amp = 100;
sin = amp * Math.sin(freq * time * Math.PI);
// creates a toggle animation 100 on/off
if (sin < 0) sin = -100;
if (sin > 0) sin = 100;
[x, y + sin]
// SINE CLIPPED (SOFT)---------------
y = position[1];
x = position[0];
freq = 1;
amp = 100;
adj = 50;
sin = amp * Math.sin(freq * time * Math.PI);
if (sin < adj && sin > -adj) {
if (sin > 0) sin = adj;
if (sin < 0) sin = -adj;
}
[x, y + sin]
// SAW ---------------
y = position[1];
x = position[0];
loopTime = 1; // loop every X seconds
t = (time - inPoint) % loopTime;
val1 = y - 100;
val2 = y + 100;
saw = linear(t, 0, loopTime, val1, val2);
[x, y + saw]
// PENDULUM ---------------
y = position[1];
x = position[0];
veloc = 10;
amplitude = 100;
decay = .1;
pendulum = amplitude * Math.sin(veloc * time) / Math.exp(decay * time);
[x, y + pendulum]
// SPIROGRAPH ---------------
y = position[1];
x = position[0];
r1 = 10; // r1 - radius of wheel A
r2 = 50; // r2 - radius of wheel B
o = 100; // o - offset
v = 5; // v - speed
s = 1.9; // s - scale
r = r1 + r2;
// x = r*Math.cos(time*v) - (r2 + o)*Math.cos(r*time*v/r2);
sy = r * Math.sin(time * v) - (r2 + o) * Math.sin(r * time * v / r2);
[x, y + sy]
// WIGGLE (CONTROLED) ---------------
y = position[1]; // not used
x = position[0];
l = 8; // loopTime (in sec)
f = 3; // frequency (per second)
a = 100; // amplituded (size)
o = 1; // octives
m = 0.5; // amp_multiplier
t = time % l; // time
w = wiggle(f,a,o,m,t);
[x,w[1]]
// WIGGLE (QUICK) ---------------
y = position[1]; // not used
x = position[0];
f = 3; // frequency (per second)
a = 100; // amplituded (size)
w = wiggle(f,a);
[x,w[1]]
Random Color Change
I'm not sure why this was so hard, but Random Colors in AE took way longer then it should have. I hope this saves someone some time. I grabbed “Change Color” from the Effects & Presets plane, dropped it onto a Black Solid that I have masked by an image layer. Next I raised the “Lightness” and “Saturation” to where I thought they felt good. Next I oppened “Hue”
x = number of seconds
f = frames per second
posterizeTime = how many frames to wait before refreshing value
random = any color value between 1° and 360°
x = 3;
f = thisComp.frameDuration * x;
posterizeTime(1 / f);
random(1, 360);
Pull in text from an external file!
I use this script a lot. It allows me to set up the text effects I want in one clip, while keeping the text in a separate txt file.
// In After Effects:
filePath = "/Volumes/your path to/TEXT.txt";
$.evalFile(filePath);
text.sourceText = eval(thisComp.name)[0]; // first position in array
// in your TEXT.txt file
/*
Text1 = ["CARDONE!","Heather is the best!"];
Text2 = ["OPTIMIZATION",""];
Text3 = ["TV APP",""];
Text4 = ["STB TV APP",""];
Text5 = ["KID'S ZONE","Until the police arrive."];
*/