Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for animating a speedometer based on spread sheet data!!!!!!!

  • Expression for animating a speedometer based on spread sheet data!!!!!!!

    Posted by Alex Kleuser on February 14, 2012 at 11:49 pm

    Hi

    I have a spread sheet with cells of data corresponding to the speed of a car at a given time. So I need an expression that will animate the needle to the data that I will copy/paste into After Effects.

    If 60.779 is the top speed, then how do I write an expression that will make 60.779 mph 100% and 0 mph, 0%?

    Below is a sample of only the first two seconds of data.

    Thanks in advance for you help!

    Time Speed
    0 0
    0.05 0.555
    0.1 0.687
    0.15 0.526
    0.2 0.767
    0.25 0.725
    0.3 0.835
    0.35 0.876
    0.4 0.923
    0.45 1.067
    0.5 0.9
    0.55 1.119
    0.6 1.292
    0.65 1.217
    0.7 1.208
    0.75 1.297
    0.8 1.481
    0.85 1.501
    0.9 1.44
    0.95 1.535
    1 1.683
    1.05 1.743
    1.1 1.756
    1.15 1.884
    1.2 1.908
    1.25 1.961
    1.3 2.113
    1.35 2.066
    1.4 1.986
    1.45 2.122
    1.5 2.337
    1.55 2.248
    1.6 2.322
    1.65 2.279
    1.7 2.418
    1.75 2.497
    1.8 2.468
    1.85 2.551
    1.9 2.463
    1.95 2.537
    2 2.656

    Jason Jantzen replied 9 years, 9 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    February 15, 2012 at 1:25 am

    I’m not sure how you’re planning on getting the data into AE (I’d use a script) but once you have it, it’s easy to convert the range using the linear() function:

    convertedSpeed = linear(inputSpeed,0,60.779,0,100)

    Dan

  • Alex Kleuser

    February 15, 2012 at 3:24 pm

    Hey thanks for the response!

    I really don’t know anything about programing or scripts so I don’t know how to design this code.

    I’d be willing to input the data manually if I have to. Or at least copy/paste and add in the commas where I need them.

    The expression…

    convertedSpeed = linear(inputSpeed,0,60.779,0,100)

    …gives me an error saying…

    “Class ‘global’ has no property or method named ‘input speed’.”

    I attached a screen shot of my AF scene with the error.
    Can you help me get set up to the point that I just need to input the data for ‘time’ and ‘speed’?

    Thanks again!

  • Dan Ebberts

    February 15, 2012 at 6:06 pm

    >…gives me an error saying…

    Sure–you need to tell the expression where to find the data. Let’s say you had the data applied as keyframes to a slider control. Then the expression would look like this:

    inputSpeed = effect(“Slider Control”)(“Slider”);
    convertedSpeed = linear(inputSpeed,0,60.779,0,100)

    The tricky part is getting your data into AE as keyframes. If you were to do it by script, the script would need to read your spreadsheet file, parse the time and speed fields, and use that info to create appropriate keyframes on a slider control (which the script might create). Of course, if you were going to go to all that trouble, you could have the script convert the data to the range you want and you wouldn’t need the expression.

    Dan

  • Jason Jantzen

    August 11, 2016 at 8:51 pm

    Hey Dan,

    I used a “counter with slider” expression I believe you wrote a while back to hook up the text value to the slider so I could round off the decimals and use the prefix MPH. Where would you add the “convertSpeed” linear function to that expression? Or am I going about this wrong?

    slider = thisComp.layer("Speed Control").effect("Speed")("Slider");
    numDecimals = 0;
    commas = false;
    dollarSign = false;
    percentSign = false;
    s = slider.value.toFixed(numDecimals);
    prefix = "";
    suffix = "MPH";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";
    if(percentSign) suffix = "%";
    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 + suffix;
    }else{
    prefix + s + suffix;
    }

    Jason Jantzen
    vimeo.com/jasonj

  • Dan Ebberts

    August 11, 2016 at 9:02 pm

    I’m not sure what you’re doing, but if you wanted to map your slider to different range, I guess you could change the first part of the expression to something like this:

    slider = thisComp.layer(“Speed Control”).effect(“Speed”)(“Slider”);
    convertedSpeed = linear(slider,0,60.779,0,100);
    numDecimals = 0;
    commas = false;
    dollarSign = false;
    percentSign = false;
    s = convertedSpeed.toFixed(numDecimals);

    Dan

  • Jason Jantzen

    August 11, 2016 at 10:01 pm

    That worked perfectly! Thank you Dan!

    Jason Jantzen
    vimeo.com/jasonj

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