Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Having trouble with a custom Counter expression

  • Having trouble with a custom Counter expression

    Posted by Yuval Zolo on July 13, 2015 at 5:00 pm

    Hey Gang,

    I’m trying to create / find a number counter expression that does the following:

    1. initial number (example: 1540)
    2. End number (example: 2323)
    3. Having an option to add a comma (example: 2,323)
    4. Grow by: # (i.e. the counter will grow by 10)(Instead of counting linearly)(no: 1 2 3 4 5 6) (yes: 10 20 30 40 50)
    5. Using time interval (Example: add 10 to initial number every 25 frames)
    6. Complete Count in X frames (i.e input how many frames should the counter run from start to finish) (which will determine speed) (I understand it might have some collision with the “Grow by #”)

    Attaching a script I found in this forum which is really cool but I couldn’t get it to do exactly what I want.
    [Basically this script is awesome, is there a way to maybe add Time interval + Grow By #]<– that would solve my problem

    I’d really appreciate some help here
    Thanks!

    numDecimals = 2;
    commas = true;
    dollarSign = true;
    beginCount = 800;
    endCount = 1450;
    dur = 120;

    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";

    if (commas){
    decimals = "";
    if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
    }
    outStr = s.substr(-s.length, (s.length-1)%3 +1);
    for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
    }
    prefix + outStr + decimals;
    }else{
    prefix + s;
    }

    Dan Ebberts replied 11 years ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    July 13, 2015 at 6:19 pm

    Try it this way:


    numDecimals = 2;
    commas = true;
    dollarSign = true;
    beginCount = 800;
    endCount = 1450;
    growBy = 10;
    growByFrames = 25;

    t = time - inPoint;
    f = timeToFrames(t);
    s = Math.min(beginCount + Math.floor(f/growByFrames)*growBy,endCount).toFixed(numDecimals);

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";

    if (commas){
    decimals = "";
    if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
    }
    outStr = s.substr(-s.length, (s.length-1)%3 +1);
    for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
    }
    prefix + outStr + decimals;
    }else{
    prefix + s;
    }

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy