Fun JavaScript for After Effects
I love writing JavaScript in After Effects. You get to instantly see the results!
array(2) { ["meta"]=> array(6) { ["name"]=> string(10) "openaq-api" ["license"]=> string(0) "" ["website"]=> string(1) "/" ["page"]=> int(1) ["limit"]=> int(100) ["found"]=> int(0) } ["results"]=> array(0) { } } object(stdClass)#2 (13) { ["coord"]=> object(stdClass)#1 (2) { ["lon"]=> float(125.6081) ["lat"]=> float(9.0125) } ["weather"]=> array(1) { [0]=> object(stdClass)#3 (4) { ["id"]=> int(801) ["main"]=> string(6) "Clouds" ["description"]=> string(10) "few clouds" ["icon"]=> string(3) "02d" } } ["base"]=> string(8) "stations" ["main"]=> object(stdClass)#4 (8) { ["temp"]=> float(84.94) ["feels_like"]=> float(97.52) ["temp_min"]=> float(84.94) ["temp_max"]=> float(84.94) ["pressure"]=> int(1012) ["humidity"]=> int(82) ["sea_level"]=> int(1012) ["grnd_level"]=> int(1011) } ["visibility"]=> int(10000) ["wind"]=> object(stdClass)#5 (3) { ["speed"]=> float(2.66) ["deg"]=> int(129) ["gust"]=> float(8.21) } ["clouds"]=> object(stdClass)#6 (1) { ["all"]=> int(20) } ["dt"]=> int(1711704477) ["sys"]=> object(stdClass)#7 (5) { ["type"]=> int(2) ["id"]=> int(2093017) ["country"]=> string(2) "PH" ["sunrise"]=> int(1711661800) ["sunset"]=> int(1711705664) } ["timezone"]=> int(28800) ["id"]=> int(1705545) ["name"]=> string(11) "Los Angeles" ["cod"]=> int(200) }
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);
Random Color Tint
Sometimes you need a comp to change color, progamatically. Tint does a fair job of this. I got this code from Andy Ford. Adding this to the "Change to Color" effect also has nice results, allowing you to more subtlly control the color effects.
// fps
posterizeTime(0.1);
// R,G,B,A
var c1 = [0,0,0,0];
var c2 = [1,1,1,1];
random(c1,c2);
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."];
*/