Code Bites AE

Fun JavaScript For After Effects
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.

Download Sine.aep


// 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]]