Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Converting speed into pace and expressing it correctly

  • Converting speed into pace and expressing it correctly

    Posted by Chris Craig on August 11, 2015 at 10:14 am

    Hi everyone

    Please can someone help me with an expression.

    I would like to convert speed (km/hr or miles/hr) into pace (min/km or min/mile).

    To do this, I need to divide 60 by the speed and then express the fractions as a time.

    For example my text layer named “Pace” is currently 5.67 km/hr.

    To calculate the pace it would be 60 / Pace layer (5.67) = 10.58

    Then i need to convert the .58 into seconds

    Thanks very much

    Chris

    Xavier Gomez replied 10 years, 8 months ago 2 Members · 5 Replies
  • 5 Replies
  • Xavier Gomez

    August 11, 2015 at 12:49 pm

    Once you get your pace as decimal number in min/km, to decompose it in min:sec, you can do

    min = Math.floor(pace);
    sec = (pace-min)*60;

    This gives the seconds part as a decimal number.
    If you want a plain integer for the seconds, replace the second line by:

    sec = Math.round((pace-min)*60);

    Xavier

  • Chris Craig

    August 11, 2015 at 11:20 pm

    Thanks Xavier for your reply.

    Would this be the full expression or just the decimal to seconds? I have pasted what you have given me, but as Im rusty with expressions, Im not sure how to write the entire expression.

    Thanks a lot

  • Xavier Gomez

    August 12, 2015 at 9:15 am

    Ah ok, i started where you had troubles.
    Full expression:

    // x : input speed (unit distance/hour)
    x = 5.67;
    // pace in min / unit distance
    pace = 60/x;
    // decompose min:sec
    min = Math.floor(pace);
    sec = Math.round((pace-min)*60);
    if (sec===60){sec=0; ++min;};

    // display text :
    “pace : ” + min + ” minutes ” + sec + ” seconds per unit distance”;

  • Chris Craig

    August 12, 2015 at 10:31 pm

    Thank you so much Xavier.

    I have tried this and am coming across a slight issue. The Pace value that this expression is converting from, is a random expression on a separate layer. I thought i would be able to pick whip the “source text” of this layer and plug it in to your expression, but it appears that I can not not do that.

    Would you know how i can get the expressed value of another layer and plug it into your expression?

    Thanks again for your help in this.

  • Xavier Gomez

    August 13, 2015 at 12:52 am

    You’d have to parse the speed text and extract the number, the way to do it depends on how the text looks like.

    I think it would be a bit easier if the speed value was carried by a slider (with your random expression on it), and then collected (=pickwhipped) by both text layers (the speed and the pace one).

    In the speed text:

    x = effect(“Slider Control”)(“Slider”).value;
    “Speed : ” + x + “km/h”;

    And in the pace text, the expression from the previous post with x taking the slider value.

    Xavier

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