Lesson06 – Counter and Text Formatting

Learn how to create a counter with auto-formatting

REMINDER
If you are an absolute beginner, please start your learning by checking the essential resources below:
http://www.jjgifford.com/expressions/basics/index.html
https://helpx.adobe.com/after-effects/using/expression-basics.html
http://www.motionscript.com

1. Counter Setup

  • Create a new Text Layer
  • Add an expression to Text Layer> Text> Source Text
var num= linear(time,0,1.2,0,125000)
num
This expression animates in 1.2 seconds the counter from 0 to 125000.

2. Auto-formatting

To create a counter using the formatting $125,000.00, a few changes needs to be done.
  • Modify the variable to keep only 2 decimals
.tofixed() converts a number into a string,
keeping a specified number of decimals.
var num= linear(time,0,1.2,0,125000).toFixed(2);
num
  • Constrain the counter to always display 8 digits

while (condition) {result}
executes & accumulates a block of code
until a specified condition is satisfied.

The Meyers’ Deeper modes of expression – while:
http://provideocoalition.com/f/story/dmoe7_decisions/P3

var num= linear(time,0,1.2,0,125000).toFixed(2);
while (num.length < 9) {num = “0” + num} {num}
Our string contains 9 characters ( 8 digits, 2 decimals and a point); the condition then must be that if the string is composed of less than 9 characters, run the code until there is enough.
For example, if the value is 36.00, it will run 6 times like this:
“0”+”36.00″ = “036.00”
“0”+”036.00″ = “0036.00”

“0”+”00036.00″ = “000036.00”Remember that we are adding strings and not numbers, when
0 + 0 + 0 + 0 + 1 = 1
“0” + “0” + “0” + “0” + “1” = “00001”
  • Split the number in two with a comma
.slice(start,end: up to, but not including)
extracts part of a string
negative values select from the end of the string.
var num= linear(time,0,1.2,0,125000).toFixed(2);
while (num.length < 9) {num = “0” + num} {num};
num.slice(0,3) +”,” + num.slice(3,9)
This new result splits the string in 2 parts and glue them back together with a comma in between.
  • Add a currency symbol
“$ “+ num.slice(0,3) +”,” + num.slice(3,9)
CHECK OUT!
Dan Ebbert’s universal counter:
http://www.motionscript.com/design-guide/counter.html
DON’T FORGET
build your own presets collection to speed up your workflow
Click icon below to download presets (rename .key to .zip after download) download
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s