Skip to content

Instantly share code, notes, and snippets.

@Volorf
Last active September 23, 2019 11:39
Show Gist options
  • Save Volorf/a51188ee86ed09eaa14e506a62d29215 to your computer and use it in GitHub Desktop.
Save Volorf/a51188ee86ed09eaa14e506a62d29215 to your computer and use it in GitHub Desktop.
Counter for After Effects
// Initial and last frames of an animation.
var startKeyFrame = 30;
var endKeyFrame = 50;
// Initial and final values of a text layer.
var startValue = 500;
var endValue = 1000;
// Util vars for a calc function
var currentFrame = time/thisComp.frameDuration,
deltaKeyFrames = endKeyFrame - startKeyFrame,
deltaValues = endValue - startValue,
unit = deltaValues / deltaKeyFrames,
deltaFrames = currentFrame - startKeyFrame;
// Create the calc function.
function counterFunc () {
if (currentFrame <= startKeyFrame) {
return text.sourceText = startValue;
} else if (currentFrame > startKeyFrame && currentFrame < endKeyFrame) {
return text.sourceText = Math.round(startValue + unit * deltaFrames);
} else if (currentFrame >= endKeyFrame) {
return text.sourceText = endValue;
};
};
// Call the calc function.
counterFunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment