Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Counter expression

  • Counter expression

    Posted by Hamid Rohi-bilverdy on January 18, 2014 at 3:17 pm

    Hi

    I want to have a count up from 0 to 100.

    I have this expression here.
    startT = 0;
    endT = 4;
    beginVal = 0;
    endVal = 100;
    t = linear(time,startT,endT,beginVal,endVal);
    t.toFixed(0)

    I understand the first 4 lines. But can someone please explain to me what the 2 last lines is means? I really want to understand it. Is the t a varibel? and what does the (0) do?? Also is there anyway i can add a percent sign after the numbers, so it will start from 0% and end with 100%??
    Best regards Hamid

    Liran Tabib replied 8 years, 11 months ago 6 Members · 10 Replies
  • 10 Replies
  • Declan Smith

    January 18, 2014 at 5:04 pm

    The linear function evaluates the current time and returns a scaled value based on the parameters you have supplied. In this example, when time=0 (startT) the count starts and will start at 0 (beginVal). It will then evaluate, in a linear fashion, the next value to display until it reaches 4 seconds (endT) where it will display 100.

    So if you wanted the count to start at 3 seconds and finish at 10 seconds, you would put startT=3 and endT at 10.

    The t.tofixed(0) ensures that no digits of precision are displayed. i.e. numbers after the decimal point (you could use Math.floor(t) to achieve the same thing in this instance).

    To add a % sign on the end, alter the expression as below.

    startT = 0;
    endT = 4;
    beginVal = 0;
    endVal = 100;
    t = linear(time,startT,endT,beginVal,endVal);
    Math.floor(t) + '%'

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    “it’s either binary or it’s not”

  • Hamid Rohi-bilverdy

    January 18, 2014 at 5:44 pm

    Thank you sir. Worked as intended.

    /HRB

  • Hamid Rohi-bilverdy

    January 18, 2014 at 10:56 pm

    Btw I tried to type in words instead of values in beginVal and endVal. Offcourse an error occoured. Is it possible to make an espression where the start word and end word can be defined??

  • Declan Smith

    January 19, 2014 at 6:02 pm

    If I understand you correctly, you want to display a selection of words rather than numbers? I have modified the expression below to include an array of words. The last line uses the integer number generated by the linear function to select one of the words from the ‘words’ array.

    Note that the first element in the array is referenced as ‘0’ and the (in this case) the last one ‘9’. Such that:

    words[0] will return ‘One’
    words[9] will return ‘Ten’

    The endVal in this case is the last reference of you words array you want to display, and the beginVal is the first reference.

    words=['One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten'];
    startT = 0;
    endT = 4;
    beginVal = 0;
    endVal = 9;
    t = linear(time,startT,endT,beginVal,endVal);
    words[Math.floor(t)]

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    “it’s either binary or it’s not”

  • Hamid Rohi-bilverdy

    January 19, 2014 at 7:02 pm

    Once again, thank you and you were spot on regarding, understanding my question. As I really want to learn and understand the same time i can’t figure out the math.floor expression…..

  • George Goodman

    January 19, 2014 at 7:46 pm

    math.floor simply means round down. So a value of 1.000001 would return 1 and so would 1.99999999999999999999999999999999999999999999999999999999999999999

    “|_ (°_0) _|”

    Sincerely,

    George

  • Chandra

    March 14, 2014 at 9:02 pm

    Hi there, I am not an expressions expert but can tinker a bit with them. I have been searching the threads here for a certain type of counter.

    I want the counter to start at 0000 then end at 00032

    I have tried a bunch of things but can’t get it to work, The expression I have adds another number for example it starts at 0000 but the goes to 00010

    How can I get the expression to not add another number but turn one of the previous “0;s” into my count?

    I hope this makes sense lol, basically I want there to always only be 4 number slots and to count up. “0000”

    Thanks for your thoughts!

    Here is what I am using:

    numDecimals =0;
    commas = true;
    dollarSign = true;
    beginCount = 0;
    endCount = 23;
    dur = 23;

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

    prefix = “000”;
    if (s[0] == “10”){
    prefix = “0”;
    s = s.substr(1);
    }
    ;.0

    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;
    }

    so this adds the prefix of 2 “00” works fine until I get to 10. I tried the expression on this thread but also does not work right for my needs and not sure how to adjust it.

    Thanks for your thoughts!

    ~C

  • Declan Smith

    March 14, 2014 at 10:08 pm

    Try the expression below. Some explanation.

    startTime – The time that the counter will start
    endTime – The time that the counter will stop
    beginVal – The first number the counter will register
    endVal – The highest number the counter will count to.
    padLength – The number of leading zeros required

    startTime = 0;
    endTime = 4;
    beginVal = 0;
    endVal = 32;
    padLength=4;
    t = linear(time,startTime,endTime,beginVal,endVal);
    str = '' + t.toFixed(0);
    while (str.length < padLength) { str = '0' + str; } str;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    "it's either binary or it's not"

  • Vladimir Druts

    October 17, 2014 at 2:06 am

    Guys is there anyway to replace the regular font numbers with pictures? ie) comps or psd’s in place of the fonts for the numbers? I have created 0-9 and need to use them (hand drawn). Is there a way to link this to the script?

    Thanks a LOT!

  • Liran Tabib

    May 24, 2017 at 5:37 pm

    If you feel like saving time, and creating counter animations without coding you can use this cool Preset:
    https://www.vdodna.com/products/counter-preset/
    Cheers!

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