Activity › Forums › Adobe After Effects Expressions › Need an Expression for an counter to increase by 50’s
-
Need an Expression for an counter to increase by 50’s
Posted by Chris Kay on June 26, 2012 at 12:56 amI am creating a counter in After Effects. I need an expression that will allow the number 750 to increase rapidly by 50’s until it hits 20000. I’m really bad at creating expressions, so some help would be greatly appreciated.
Orme Dominique replied 13 years, 6 months ago 4 Members · 9 Replies -
9 Replies
-
Dan Ebberts
June 26, 2012 at 3:06 amSomething like this should work:
countStart = 750;
countStop = 20000;
increment = 50;
rate = 500; // counts per second
t = time – inPoint;
countStart + Math.min(Math.floor((t*rate)/increment)*increment,countStop)Adjust the rate to make it go faster/slower.
{edit}
That wasn’t quite right. This should work:
countStart = 750;
countStop = 20000;
increment = 50;
rate = 500; // counts per second
t = time – inPoint;Math.min(countStart+Math.floor((t*rate)/increment)*increment,countStop)
Dan
-
Orme Dominique
January 30, 2013 at 10:16 pmWould this same counter go beyond 30,000. And how would you get commas in to it? I need something just like this that goes from 100 to 5,000,000 in increments of 100. I’m not that good with expressions yet so, trying to figure this out is tricky.
-
Dan Ebberts
January 30, 2013 at 11:00 pmTry this source text expression, which should increment from 100 to 5,000,000 over 30 seconds. Of course, you’ll need to set the duration to be much longer if you want to see each increment of 100.
tStart = inPoint;
dur = 30;
startVal = 100;
endVal = 5000000;
val = linear(time,tStart,tStart+dur,startVal,endVal);
newVal = Math.round(val/100)*100;
newVal.toString().replace(/B(?=(d{3})+(?!d))/g, “,”);Dan
-
Orme Dominique
January 31, 2013 at 7:35 pmThanks, Dan. I’ll give a try and let you know. BTW do you have any suggestion for learning and or training resources for someone that wants to get into doing expression full on?
-
Orme Dominique
February 1, 2013 at 6:40 amWell it seems to work, it counts up but I can’t get the commas to work. I wish I could figure this out. I think this part is
newVal.toString().replace(/B(?=(d{3})+(?!d))/g, “,”);
that does the trick, but I can’t figure out why its not working. Let me know if you have any thought, which I’m sure you do.
-
Orme Dominique
February 4, 2013 at 6:06 pmHey Dan,
Can you help me me with the commas on this one. It’s incerment just fine but the commas aren’t working.
I was poking around and I found this script on your Motion Script site it works pretty well but I can’t figure how to make it increment. I like how you outline what each section is doing, it helped understand it for sure. I need to get a lot better at doing expressions, its one of my goals this year.
numDecimals = 2;
commas = true;
dollarSign = true;
beginCount = -1999;
endCount = 1999;
dur = 4;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;
} -
Lucas Poeschel
February 7, 2013 at 6:12 amWere you able to get an answer on this, this is the only thread i can find for a counter that both increments and has commas however it stops short of the solution. I am wonder if anyone has figured this out, thanks.
-
Orme Dominique
February 7, 2013 at 7:42 amThank God for Dan… in fact he is a god. He gave me the key which is basically turning this
s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);
to this:
s = (Math.floor(linear (t, 0, dur, beginCount, endCount)/100)*100).toFixed(numDecimals);
The full working is right down below. Be sure to give a shout out to Dan.
numDecimals = 2;
commas = true;
dollarSign = true;
beginCount = -1999;
endCount = 1999;
dur = 4;t = time - inPoint;
s = (Math.floor(linear (t, 0, dur, beginCount, endCount)/100)*100).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;
}
Reply to this Discussion! Login or Sign Up