Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Throttle Airspeed expression

  • Throttle Airspeed expression

    Posted by Joe Poisson on August 27, 2012 at 8:47 pm

    Hi all,

    I’m making a dynamic readout based on one Expression Slider called Knots, which is set to slide between 100-1650 (roughly MACH 2.5). This gets linked into a text layer. The word “KNOTS” get replaced by the word “MACH” when the speed of sound is achieved and also the numerical readout goes into “Mach mode” where it shows the Mach value instead of Knots.


    v=thisComp.layer("Throttle Controller").effect("Knots")("Slider")
    K=" KNOTS"
    M=" MACH"
    mNum=Math.round(v/661.7*1000)/1000
    if (v>661.7) (TXT=M) else (TXT=K);
    if (v<661.7) (""+Math.round(v)+TXT) else (""+mNum+TXT)

    The trouble I am having is that I want MACH Mode to always show 3 decimal places. And actually, now that I look at this code, I’d like to change the visual style and show BOTH Knots and Mach. Getting them both to display shouldn’t be a problem, but how can I get the Mach section to always show 3 decimals (i.e. 0.500 or 1.300 instead of .5 or 1.3)?

    And, for extra credit, I think it would look real nifty if the Mach line turned red and then back to white over half a second (15 frames) after hitting Mach 1. Just a little red attractor pulse.

    Oh, and I’ll add the Mach altitude conversion later when I create the altimeter. 😉

    //I guess this would be (close to) the newer expression, really guessing here
    v=thisComp.layer("Throttle Controller").effect("Knots")("Slider")
    mNum=Math.round(v/661.7*1000)/1000
    ""+Math.round(v)+" KNOTS" r
    "MACH "+""+mNum

    Joe Poisson replied 13 years, 8 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    August 27, 2012 at 9:33 pm

    Try this:

    v=thisComp.layer(“Throttle Controller”).effect(“Knots”)(“Slider”);
    mNum = v/661.7;
    “” + Math.round(v)+” KNOTS” + String.fromCharCode(10) + “MACH “+”” + mNum.toFixed(3)

    Dan

  • Joe Poisson

    August 27, 2012 at 9:54 pm

    Dan the MAN,

    Thank you so much, I replaced the String.fromCharCode(10) with a “r” and am in business. This next I ask only for my own knowledge, NOT to slight your much appreciated help in any way. Your written expression had everything on one line and no space between KNOTS & MACH.

    ex. 650 KNOTSMACH 0.953

    What does String.fromCharCode(#) do?

    Thanks again!

  • Dan Ebberts

    August 27, 2012 at 10:02 pm

    >Your written expression had everything on one line and no space between KNOTS & MACH.

    That’s strange. It generates two lines here.

    String.fromCharCode(10) should give you a carriage return, like backslash + r. I started using it here because the site HTML eats backslashes, but if it doesn’t work in all cases I’ll have to reconsider. Are you on a Mac?

    Dan

  • Joe Poisson

    August 27, 2012 at 10:11 pm

    No, PC running 5.5 x64.

    Seriously tho, potato/potatoe as long as it works, right?

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