Skip to content

Instantly share code, notes, and snippets.

@monsieuroeuf
Created March 16, 2016 03:12
Show Gist options
  • Save monsieuroeuf/749315d600737ee0e543 to your computer and use it in GitHub Desktop.
Save monsieuroeuf/749315d600737ee0e543 to your computer and use it in GitHub Desktop.
After Effects expression: automatic motion with expo easing
// Ian Haigh : http://ianhaigh.com/
// automatic motion for After Effects with expo easing
// set up sliders to easily change the values
function easeandwizz_inExpo(t, b, c, d) {
var IN_EXPO_CORRECTION = 0.000976;
return t==0 ? b : c * (Math.pow(2, 10 * (t/d - 1)) - IN_EXPO_CORRECTION) + b;
}
function easeandwizz_outExpo(t, b, c, d) {
var OUT_EXPO_CORRECTION = 1.000976;
return (t==d) ? b+c : c * OUT_EXPO_CORRECTION * (-Math.pow(2, -10 * t/(d)) + 1) + b;
}
var slideDuration;
try { var inDistance = effect("inDistance")("Slider") } catch(e) { var inDistance = 1920 }
try { var outDistance = effect("outDistance")("Slider") } catch(e) { var outDistance = 1920 }
try { var slowSlideDistance = effect("slowSlideDistance")("Slider") } catch(e) { var slowSlideDistance = 0 }
try {
if (effect("flip direction")("Checkbox") == true) {
slowSlideDistance *= -1;
outDistance *= -1;
inDistance *= -1;
}
} catch(e) {}
try {
slideDuration = effect("slideDuration")("Slider");
} catch(e) {
slideDuration = 0.5;
}
if ((time >= inPoint) && (time <= inPoint + slideDuration)) {
var normalisedTime = linear(time, inPoint, inPoint + slideDuration, 0, 1);
easeandwizz_outExpo(normalisedTime, value-inDistance, inDistance, 1);
} else if ((time > outPoint - slideDuration) && (time <= outPoint) ) {
var normalisedTime = linear(time, outPoint - slideDuration, outPoint, 0, 1);
easeandwizz_inExpo(normalisedTime, value + slowSlideDistance, outDistance, 1);
} else {
linear(time, inPoint + slideDuration, outPoint - slideDuration, value, value + slowSlideDistance);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment