Escolar Documentos
Profissional Documentos
Cultura Documentos
http://aeexpressions.blogspot.de/
Diese Website verwendet Cookies, um die Bereitstellung von Diensten zu verbessern. Durch die Nutzung dieser Website erk
LINKS
Expressions Training
Thanks for checking out this old Expressions blog!! This was an early
test to get the ball rolling on my Expressions training series. It's hard
to explain this stuff, so I wanted to kick it around for a while before
creating a series on it. The older this gets, the closer I get to deleting
this blog, as I have learned so much since I posted this stuff.
However, I'll leave this up for now. But if you want more info on
Load Testing
101
smartbear.com/L...
graymachine
AE Freemart
5 4 C O MME NTS
PREVIOUS POSTS
Expressions Training
Lesson 6: thisComp
Lesson 6: thisComp
Lesson 4 : If/Else
There are some useful terms to learn that we can use to get a great
deal of information about a composition, as well as the elements
inside the compostion. Please note that all of the examples are CASE
Lesson 3: Value
Lesson 2: Arrays and Variables
Lesson 1: The Basics
SENSITIVE!!
thisComp.height
This returns the height of your comp in pixels. For example, for a
NTSC D1 composition, thisComp.height would be equal to 486.
ARCHIVES
July 2006
August 2006
September 2006
June 2007
thisComp.width
This returns the width of your comp in pixels. For example, for a
NTSC D1 composition, thisComp.width would be equal to 720.
thisComp.numLayers
This returns the number of layers in your current composition.
To demonstrate a simple example, let's consider the following
expression as applies to Position:
1 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
x = value[0];
y = thisComp.height/(thisComp.numLayers/index);
[x,y]
Two-dimensional position is array, therefore it has two values: one
for x and one for y. To have X position be freely editable in an
expression, using 'value[0]' will leave the existing x position (position
value number "0").
Next, we declare a calculation for Y. The value of the comp height
divided by the number of layers in the comp divided by the index.
Recall that 'index' is equal to the current number of the layer.
If we plug this expression into Position for just one layer (with only
one layer in the comp), it will position the layer at the bottom of
your composition. For example, 486 / (1 / 1) = 486.
However, if duplicates of this layer are made, each one will
automatically distribute itself equally in Y.
Some other useful uses of this comp are as follows:
thisComp.duration
Returns the length of the comp in seconds.
thisComp.frameDuration
Returns the duration of one frame in time in seconds.
1/thisComp.frameDuration would return your current frame rate.
PO STE D BY H A R R Y A T 9 :0 3 A M
8 C O M ME NTS
2 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
Here, I typed everything out first, before entering the code from the
pick-whip, to illustrate things more clearly. Notice that I PUT THE
CURSOR WHERE I WANT THE CODE TO GO. Don't forget to put a
3 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
semicolon, either.
You'll see now that dragging the Expression Slider on Null 1 makes the
scale of the solid change, but the anchor point is in the wrong spot
and needs to be moved to the bottom (double-click the solid layer
and move the anchor to the bottom). After moving the anchor, you'll
have to reposition your solid, as you'll notice that it has moved.
Next, the type needs to be driven by the slider, too. Twirl open the
type layer, and locate the "Source Text". Create an expression for
this and drag its pickwhip to the slider as well.
What you'll see is that the bar and data label now work in sync,
driven by an expression. GREAT! But, there's a couple problems.
First, try this: animate the slider value from 0 to 50.
The value of the data label is reflecting the extreme accuracy of the
Expression Slider by showing a great number of decimal values. We
want to round that off.
Let's learn a new term:
4 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
Math.round(value)
Simply put, Math.round rounds what is inside the parantheses to the
nearest whole number.
In our example, declare the code that we got via the pickup to be
equal to a variable, like this:
sliderVal = thisComp.layer("Null 1").effect("Slider Control")
("Slider");.
At this point, we could round this by using "Math.round(v)". However,
what that would do is round v to the nearest integer, but we should
get this to tenths as we should show a little more accuracy. To do
this, we need to use a common Javascript technique thata goes like
this:
Math.round(value*10)/10
Within Javascript/Expressions, this does exactly the trick. Multiplying
the number to be rounded by 10, then dividing by 10 will round the
number to tenths. Pretty cool.
But notice one more problem, and this stumped me for a bit. On
integer numbers, there are no tenths. Javascript has no reason to
show them whatsoever, as "25.0" and "25" are identical to a
computer. But, aesthetically, we would want our numbers to ALWAYS
be in tenths, rather than jump around from tenths to whole numbers
and back again. You'd think there would be a very easy way to do
this, but there really isn't.
To figure out how to do this, we need to learn about one more thing:
"modulus". Modulus is an "operator", just like plus, minus, divide, and
multiply ( + - / *). Modulus is expressed with the following term:
%
What this does is return the remainder after dividing two numbers.
For example:
17 % 5
This would return "2". 17 /5 = 3 with a remainder of 2.
10 % 5
This would return "0". 10 /5 = 2 with a remainder of 0.
SO, let's think out our decimal problem in plain English:
If the value of the expression slider is integer,
then we need to add a ".0" to the end of the number.
5 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
otherwise,
leave the number alone.
So, we have our variable, I'll use 'sliderVal' in this case:
v = thisComp.layer("Null 1").effect("Slider Control")("Slider");
We need to check to see if this number is an integer or not. I did this
by doing this:
check = v % 1
I declare the variable "check" to be equal to the remainder of y
divided by 1. If check is "0" the number is integer, if not the number
is non-integer. See where we are going with this? Let's cut to the
chase and show the code:
sliderVal = thisComp.layer("Null 1").effect("Slider Control")("Slider");
v = Math.round(sliderVal*10)/10;
check = v % 1
if (check == 0){
"" + v + ".0"
}else{
v
}
OHMIGOSH, you might be saying.
Don't panic.
First, we have a variable with a bunch code that we got by using the
pickwhip. Don't even worry at this point what it all means:
sliderVal = thisComp.layer("Null 1").effect("Slider Control")("Slider");
Then, we round sliderVal to tenths:
v = Math.round(sliderVal*10)/10;
Next, we test to see if we have a number that is integer (with no
decimal) or non-integer (with a decimal). We do this by declaring a
variable to be equal to the remainder of the result of v divided by 1,
which is expressed as:
check = v % 1
Next, think back to the format of if/else:
if (condition){
result1
}else{
result2
}
6 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
3 C O M ME NTS
7 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
Lesson 4 : If/Else
In previous topics, we've covered some basic ways to define or modify
parameters using After Effects expressions. But let's do something a
little more complex to start harnessing the practical side of
expressions.
What we discussed in prior topics was how to create some values
based on time, or index. But, these values were always absolute.
There is nothing telling After Effects that "if this value reaches a
certain point, then do something else". This is exactly what if/else is
for.
Consider the following example. Put this on the position of, perhaps,
a type layer.
xPos= time * 200 ; yPos = position[1] ;
[ xPos , yPos ]
If you've been reading the other blogs, this should mostly make sense,
but let's review.
We declare a variable "xPos" to be equal to time multipied by 200.
Remember, time is the current time of the AE playback head or "CTI".
As the time in the comp time becomes greater, the value of the term
time increases. Therefore, as time in the comp progresses, the text
moves in a postive direction in the X axis.
Next, we provide AE with the values that we want our position to be.
Unlike parameters like opacity that are defined by one number,
position is defined by multiple numbers (x and y, in this case), which
we call an array. When we provide AE with the values for an array,
we need to use this kind of format:
For a 2d layer:
[x,y]
or for a 3D layer:
[ x , y, z ]
So in our example, [ xPos , yPos ] is providing the x and y values.
xPos =========> is X
yPos =========> is Y
8 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
9 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
6 C O M ME NTS
Lesson 3: Value
In this lesson, we are going to explore the term value.
In short, value returns (or "gives you") the current value of whatever
parameter which with you are working.
So, if we were to use the following expression on opacity:
value + 5
The opacity is still modifiable, because the expression is getting the
current value of the parameter as is, and then adding 5 to it. value
always leaves your parameter modifiable, but with the ability to
combine different calculations with it.
For example, using our simple Opacity scenario, try adding the
following expression:
10 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
This will result in opacity gradually increasing the opacity over time.
But unlike before, you'll notice that we can now modify the value of
Opacity. Why is that?
The term value is the current parameter value, as is. This we can
change as we please. To this, we add the time.
If we only used the term time, opacity would increase by 1 for every
1 second that passes in the composition, and we would not be able to
change the value
So, for an example, let say we wanted to create a name banner that
we can move around as we please, but still had movement of its own
generated with expressions.. value would allow this flexibility.
Remember my awesome train drawing?
value, when used with an array will have multiple values. To work
with these values, we need to specify what value we want. The way
we do this is with the [0], [1], etc. Don't forget that it is ZERO that is
the first number, not one. So what we would call the first value
would be:
value[0]
11 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
4 C O M ME NTS
12 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
Think of an array like one big train. Instead of hauling freight and
hobos, it is hauling numbers. Each compartment is separate, but in a
distinct order. In the case of 3D position, we have XYZ as the values
you might want to call 1 , 2 , & 3. We'll learn later on that AE
logically refers to values 1 2 & 3 as 0, 1 & 2.
So, the easy example that we had with opacity gets trickier here.
There's a fairly specific way we need to define arrays in expressions,
and that goes a little something like this:
[x,y,z]
So, to define simple numbers for these values, the following
expression shows you how to place an obect at 100, 200, 300 in 3D
space:
[ 100, 200, 300]
The brackets are absolutely necessary and AE will return an error if
you don't put them there. Spaces are mostly ignored, however. I use
a lot of here to make things easier to read.
Now, for a few new concepts:
First, the "variable". A variable is simply an 'unknown value' that we
want to calculate or assign a value to. Look at the following example.
x = 100 y = 200 z = 300 [ x , y , z ]
This has exactly the same result as the first expression: [ 100, 200,
300]. We are just presenting it in a different way. Variable are often
handy just like we use pronouns. I could say Rufus Xavier
Sarsasparilla.. or I could say "he" once I establish who "he" is.
In exactly the same way, I can declare a variable to be a number, or
calculation or any number of things and refer to "x" rather than using
the calculation every time. This makes the code shorter, less
13 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
14 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
That wraps it up for now. Next time we'll explore how to leave the X
, Y and Z values adjustable in this example, while still having the
layers spaced in Z.
PO STE D BY H A R R Y A T 1 0 :2 7 A M
8 C O M ME NTS
15 of 17
7/14/14 2:50 PM
http://aeexpressions.blogspot.de/
Let's throw in another expression term: time. Any time we use the
word "time" in an expression, time will be equal to the current time
of the composition playback head in seconds. So, if you play your
comp from the beginning, time will start at 0 and increase 1 for
every second that passes.
If we add this expression to opacity:
10 + time
Opacity will start at 10 and increase by one every second. Note that
once the values go beyond 100, the value remains at 100.
Let's try multiplying.
time*100
Things were moving pretty slow before. This picks up the pace quite
a bit. We are simply using time multiplied by 100 as the value for
opacity rather than using keyframes.
What if we wanted this to start at 5 seconds? There are more elegant
ways to do this, but let's do this the easy way:
(time * 100) - 500
Time keeps moving on, ya know. So, at 5 seconds, (time * 100) will
be equal to 500. Again, opacity treats any value over 100 as 100 and
any value below 0 as 0. So, if we subtract 500, the opacity will not
start changing until 5 seconds.
One thing that I don't want to skip over is the parenthesis. Remember
back to basic math class... mine was with Mrs. Fleeger. There's an
accepted way that we calculate things. Often people use the term
"BEDMAS" to remember this. This means that the order we calculate
our equation is in this order: brackets (or parentheses), exponents,
division, multiplication, addition, subtraction.
The reason I bring this up is that in the above example, we have some
parenthesis. The items inside the parenthesis will get calculated
FIRST. Then that calculation will have 500 subtracted from it. For
example, at 3 seconds we would have:
(3 * 100) - 500 = (300) - 500 = -200
As I mentioned, negative opacity values are treated as 0. We cannot
have a negative opacity obviously. This value will continue to be
negative until we reach 500 inside the parantheses, which is 5
seconds.
Absorb that for now, and then next time I'll cover Array values like
Position and Scale. Don't know what that means? Then check back.
PO STE D BY H A R R Y A T 8 :4 1 A M
16 of 17
1 9 C O MME NTS
7/14/14 2:50 PM
17 of 17
http://aeexpressions.blogspot.de/
7/14/14 2:50 PM