Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Gas Pump Price/Gallon Expression

  • Gas Pump Price/Gallon Expression

    Posted by Dylan Harrelson on February 11, 2015 at 1:35 am

    I’ve had the idea to make a comp that would show the rise in price / gallon at the pump. Can this be done by slider controls? One that sets the price per gallon and/or the amount of gasoline.

    Using Dan Ebbert’s universal currency / count expression I’ve slightly modified the expression code for a time slider and total amount of gas, however I need the total amount to equal the number of gallons times price at the time. Any assistance would be greatly appreciated.

    numDecimals = 2;
    commas = true;
    dollarSign = true;
    beginCount = 0;
    endCount = effect("PRICE SLIDER")("Slider")
    dur = effect("TIME")("Slider");

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

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";

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

    Dylan Harrelson replied 11 years, 3 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    February 11, 2015 at 3:17 am

    I don’t know that that expression is necessarily the right tool for the job. What is it that you’re trying to do, exactly? (What does the finished product do?)

    Dan

  • Dylan Harrelson

    February 11, 2015 at 10:24 am

    Preferably I want to display the readout of a gas pump. If gas was 1.99/gallon and I used 10.0 gallons it would display the total cost and the amount of gas used.

    Basically the example attached from VideoHive but controlled by slider parameters to set price per gas and total fuel.

    Gas Pump Display

    Dylan Harrelson
    Digital Media Professional

  • Dan Ebberts

    February 11, 2015 at 2:22 pm

    I think I would put sliders for price and gallons per second on a null layer named “controls” and then have a text layer with this expression for the cost:

    price = thisComp.layer(“controls”).effect(“PRICE SLIDER”)(“Slider”);
    galPerSec = thisComp.layer(“controls”).effect(“GAL/SEC SLIDER”)(“Slider”);
    (price*galPerSec*time).toFixed(2);

    and another text layer with this expression for the gallons:

    galPerSec = thisComp.layer(“controls”).effect(“GAL/SEC SLIDER”)(“Slider”);
    (galPerSec*time).toFixed(3);

    Dan

  • Dylan Harrelson

    February 11, 2015 at 7:29 pm

    This works great Dan. Very much appreciated.

    Dylan Harrelson
    Digital Media Professional

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