Skip to content

Instantly share code, notes, and snippets.

@seblavoie
Last active March 3, 2017 03:05
Show Gist options
  • Save seblavoie/4012237 to your computer and use it in GitHub Desktop.
Save seblavoie/4012237 to your computer and use it in GitHub Desktop.
Useful animation expressions
// Link with expression
l = thisComp.layer("Layer Name");
p = l.toWorld(l.anchorPoint)
// Opacity jittering in
transitionTime = 1;
if (time < transitionTime) {
(random() < 0.5 ? 0 : 100);
} else {
100;
}
// Keyframe Bounce Back
// Source: http://www.motionscript.com/articles/bounce-and-overshoot.html#kf-bounce-back
e = .7;
g = 4000;
nMax = 9;
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time) n--;
}
if (n > 0){
t = time - key(n).time;
v = -velocityAtTime(key(n).time - .001)*e;
vl = length(v);
if (value instanceof Array){
vu = (vl > 0) ? normalize(v) : [0,0,0];
}else{
vu = (v < 0) ? -1 : 1;
}
tCur = 0;
segDur = 2*vl/g;
tNext = segDur;
nb = 1; // number of bounces
while (tNext < t && nb <= nMax){
vl *= e;
segDur *= e;
tCur = tNext;
tNext += segDur;
nb++
}
if(nb <= nMax){
delta = t - tCur;
value + vu*delta*(vl - g*delta/2);
}else{
value
}
}else
value
// Source: http://www.motion-graphics-exchange.com/after-effects/Wiggle-rubber-bounce-throw-inertia-expressions/4ad0f32a944ad
// Jumpy Wiggle 1 makes wiggle skip and hold rather than move fluidly.
// Jumpy Wiggle 1 (moves at a random FPS)
v=wiggle(5,50);
if(v < 50)v=0;
if(v > 50)v=100;
v
// Jumpy Wiggle 2 is similar to 1, but works at a defined FPS so your "jump" will happen at a regular pace.
// Jumpy Wiggle 2 (moves at a defined FPS)
fps=5; //frequency
amount=50; //amplitude
wiggle(fps,amount,octaves = 1, amp_mult = 0.5,(Math.round(time*fps))/fps);
// Inertial Bounce is like making your moves "rubbery." Layers will overextend, then settle into place on position and rotation keyframes.
// Inertial Bounce (moves settle into place after bouncing around a little)
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time){
n--;
}
}
if (n == 0){
t = 0;
}else{
t = time - key(n).time;
}
if (n > 0){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
amp = .05;
freq = 4.0;
decay = 2.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}
// Sometimes you just want something to move constantly without keyframing it. Use throw.
// Throw (move at a constant speed without keyframes)
veloc = -10; //horizontal velocity (pixels per second)
x = position[0] + (time - inPoint) *veloc;
y = position[1];
[x,y]
// Same as throw, but for rotation.
// Spin (rotate at a constant speed without keyframes)
veloc = 360; //rotational velocity (degrees per second)
r = rotation + (time - inPoint) *veloc;
[r]
// By Chris Wright
// Flip anchor point side according to keyframe value
// Transform anchor point
[-content("Rectangle Path 1").size[0] / 2, value[1]] * (effect("Flip")("Checkbox") == 1 ? -1 : 1)
// Transform position
x = (effect("Flip")("Checkbox") == 1 ? effect("Width")("Slider").valueAtTime(effect("Width")("Slider").key(2).time) : 0);
value + [x, ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment