Last active
November 15, 2016 16:23
-
-
Save monsieuroeuf/7922841 to your computer and use it in GitHub Desktop.
After Effects expression that increments a number, with Ease and Wizz easing. It takes the start value from the name of the text layer, and the end value from a marker comment on that same layer. #easeandwizz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Count up to a specified value in a given amount of time. | |
// With commas! If you're into that kind of thing. | |
// how to set up … | |
// start : this layer's name (i.e. call it an integer like "0") | |
// duration: add an expression slider called "duration" | |
// total: add a marker with a comment, that's the number to count up to | |
// delay: edit the value below | |
var DELAY = 0; // time to begin counting | |
function easeandwizz_inOutCirc(t, b, c, d) { | |
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; | |
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; | |
} | |
function easeandwizz_outExpo(t, b, c, d) { | |
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; | |
} | |
var m = thisLayer.marker.nearestKey(time); | |
var BEGIN = parseInt(thisLayer.name); | |
var DURATION = effect("duration")("Slider"); // seconds | |
var TOTAL = parseInt(m.comment); // number to count up to | |
addCommas(count()); | |
function count() { | |
var normalised = linear(time, inPoint + DELAY, inPoint + DURATION + DELAY, 0, DURATION); | |
return Math.floor(easeandwizz_outExpo( normalised, BEGIN, TOTAL - BEGIN, DURATION )); | |
} | |
function addCommas(nStr) { | |
// from http://www.mredkj.com/javascript/nfbasic.html | |
nStr += ''; | |
x = nStr.split('.'); | |
x1 = x[0]; | |
x2 = x.length > 1 ? '.' + x[1] : ''; | |
var rgx = /(\d+)(\d{3})/; | |
while (rgx.test(x1)) { | |
x1 = x1.replace(rgx, '$1' + ',' + '$2'); | |
} | |
return x1 + x2; | |
} | |
// After Effects expression | Ian Haigh | ianhaigh.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You rock. Thank you!