Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for Digital Clock

  • Expression for Digital Clock

    Posted by Matthewb on March 13, 2006 at 10:25 pm

    Dan/Anyone

    in a past posting: “Expressions for a Digital 24 Hour Clock” https://forums.creativecow.net/cgi-bin/new_read_post.cgi?forumid=2&postid=873535

    you posted a source text exprssion:
    https://forums.creativecow.net/cgi-bin/new_read_post.cgi?forumid=2&postid=862284

    i have to write a clock that starts at a specific point and stops at a specific point over a specified period… i.e. clock starts at 30.0 seconds and over 2 second climb to 43.14 seconds.

    i am new to this and can rework your expression but am confused on a couple things:

    what is taking place here in your expression:
    function digits(myVal,myNumDigits){
    var s = myVal.toString();
    while (s.length < myNumDigits) s = '0' + s; return s; } i can follow the rest but am having trouble with what "function" is performing (adobe help, wasnt) then waht is the digits command accomplishing... s i take it is getting the length of myVal i think i can figure it from there... just am not sure what is happening at the beginning... thanks,

    Ryan Hill replied 20 years, 2 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    March 14, 2006 at 12:38 am

    The digits() function just converts an integer value to a specified number of text digits, padding the front with zero as necessary. For example, digits(9,3) would give you the string “009” (I think).

    Dan

  • Dan Ebberts

    March 14, 2006 at 12:59 am

    It sounds like you might just need something like this expression applied to the source text of a text layer:

    t = linear(time,0,2,30,43.14);
    str = “” + Math.round(t*100);
    str.substr(0,str.length-2) + “.” + str.substr(-2)

    Dan

  • Matthewb

    March 14, 2006 at 2:47 am

    Thanks Dan, I greatly appreciate your site motionscript.com! it is educating me quite a bit! but i also think i need to get a book to study more in depth!. your solution works great! Thanks

  • Ryan Hill

    March 14, 2006 at 3:35 pm

    In the code you quoted, “function” is defining a function. In this case, that function is called digits.

    I expect that later in the expression, there’s something like:
    digits(timecode,4);

    When it reaches this point, because digits has already been defined as a function, it executes the code contained within the { } with the values of myVal=timecode and myNumDigits=4.

    Defining functions is something that’s useful sometimes to organize large amounts of code, or to re-use the same code multiple times.

    Does this make sense?

  • Matthewb

    March 14, 2006 at 11:13 pm

    Thanks that does help quite a bit! I come from a bit of a Pascal programming experiance so i am having to crosstrain my thoughts into java… so your explaintion helps to understand the procedures, thanks again

  • Ryan Hill

    March 15, 2006 at 2:31 pm

    I think Pascal has functions.

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