ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

number counter

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT
rubefink
number counter
on Oct 16, 2007 at 10:18:22 pm

I'm trying to create a simple looking number counter. It has to go from zero to 130,000 then back to 1,000. I tried using the number Effect but it taps out at 30,000 for some reason and I need to go higher. Does anyone have any ideas? If the answer is using expressions well I know very little of that so you'de have to break it down for me. I saw the odometer tutorial but this job doesn't need anything that fancy. Just numbers changing in sequential order would be great. Thanks.

- rube


Return to posts index

yikesmikes
Re: number counter
on Oct 17, 2007 at 12:09:35 am

Here's a Dan expression that goes on Source Text, link below.

1) Put any letter on the screen where you want it with the Text Tool, the font you want and the size you want for your counter.

Add the following expression for Source Text (Copy the expression, Alt-Click the Source Text Stopwatch, Paste, click outside the box):

numDecimals = 0;
commas = true;
dollarSign = false;
beginCount = 0;
endCount = 130000;
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;
}


This will count from zero to 130,000 in four seconds (dur, line 6 in code above).

To go from 130,000 back to 1000, first trim that first text layer (Alt }) then I'd duplicate the Text layer, slide it back until it takes over where the first text layer stops, then change the expression, line 4 to;

beginCount = 130,000;

and line 5 to:

endCount = 1000;

That should do it. Dan's expression lives here for a complete explanation:

http://www.motionscript.com/design-guide/counter.html




Return to posts index

rubefink
Re: number counter
on Oct 17, 2007 at 3:25:57 am

thanks much. I'll try this out first thing tomorrow.


Return to posts index


rubefink
Re: number counter
on Oct 17, 2007 at 3:51:38 pm

Your suggestion worked perfect.
Much thanks.


Return to posts index

Troy Ruff
Re: number counter
on Mar 27, 2010 at 6:48:28 pm

Thank you thank you, I have been trying to figure out how to do this and with no suggests until now, it works beautifully . Thanks so much.

Troy

Troy Ruff


Return to posts index

Jonny Hal
Re: number counter
on Dec 8, 2011 at 4:48:39 am

Thanks so much -- really helped me out.


Return to posts index


Leandro Sarmento da Silva
Re: number counter
on Jun 29, 2012 at 8:22:24 pm

Helped me a lot!
I made some modifications to this expression, to make it the most common AE FX.
As an example, add a "Slider Control" on the key frame.
example:

effect ("Slider Control") ("Slider") added in place of the value of "beginCount" and "endCount"

beginCount = effect ("Slider Control") ("Slider");
endCount = effect ("Slider Control") ("Slider");


So you have control over the length "dur"
What you can put as "0"

For only with such modifications you already have the control when it starts and ends when through the key frame.


Return to posts index

Danielle See
Re: number counter
on May 15, 2013 at 2:32:30 pm

Another thank you from me, I'm so stoked with this!!


Return to posts index

Ernesto Sanchez
Re: number counter
on Mar 24, 2014 at 7:06:11 pm

I'm working on a project and I used this code and it works great, thank you for that!

I'm trying to include text at the end of the number, for example, I have the the counter ending at $4.2 but I wanted to add the "M" after the number 2, how can I do that.

Please help.


Return to posts index


Dan Ebberts
Re: number counter
on Mar 24, 2014 at 7:36:01 pm

You should be able to change the last 4 lines to something like this:

prefix + outStr + decimals + "M";
}else{
prefix + s + "M";
}


Dan



Return to posts index

Ernesto Sanchez
Re: number counter
on Mar 24, 2014 at 8:44:00 pm

It worked! Thank you Dan!


Return to posts index

Jim Darski
Re: number counter
on May 12, 2017 at 1:25:53 am

Hi Dan,
Is there any way to mix different font size and color? It seems they do not carry over from the original text.
Thanks,
Jim


Return to posts index

Dan Ebberts
Re: number counter
on May 12, 2017 at 3:36:25 am

Unfortunately, everything gets the same formatting as the first character. You could a Fill Color Animator, but that doesn't help you with font size. If it's important, you'll probably need to use separate text layers and use sourceRectAtTime() to position the pieces horizontally.

Dan



Return to posts index

Lara Malas
Re: number counter
on Mar 16, 2020 at 4:37:24 pm

How can I add a zero before the number? so it goes 01-02-03 etc? I'm trying to make a clock ticker go up


Return to posts index

Liran Tabib
Re: number counter
on Apr 22, 2016 at 6:53:13 am

A new Tool to solve this old problem.
I created a Counter Preset to create any Counter and running numbers animation. I hope you will find it useful. you can get it here:
http://www.vdodna.com/products/counter-preset/


Return to posts index

Quentin Guestin
Re: number counter
on May 12, 2017 at 3:39:07 pm

There is a free preset on a french forum :
http://motion-cafe.com/preset-counterpro

It's based on the Dan's expressions. It's very useful !


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT
© 2020 CreativeCOW.net All Rights Reserved
[TOP]