Friday, July 28, 2006

Lesson 2: Arrays and Variables

Previously, we covered how to use some basic expressions using opacity. Opacity has a single value, as it is defined as a one number from 0 to 100. But not all parameters are that simple.

For instance, consider position. This could have 2 or even 3 values... X Y & Z.

So, when I mentioned how we could simply put an expression that said "5" for opacity to make the opacity a value of 5, that was easy enough. But, the parameters that have multiple values make things trickier.

First off, let's learn the lingo. A parameter that has more than one value is called an "array".

First off, check out this AWESOME picture I drew. Yeah, it's pretty much the best drawing I ever made.

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 cluttered looking, and faster for AE to go through.

Variable names can be any set of characters that AE does not use as a specific function. For instance, we cannot use the word 'time' as a variable. But we could use myTime, or hammerTime, or millerTime. When using multiple variables in a project, it is useful to use variable that make sense, like "posX" or "startTime". You'll come up with your own style, but just know that variables can be "x" or "x1" or "xFactor" or "myReallyLongVariableName". It's up to you.. they do not have to be "x" or "y" or "z".

One more term to learn today: index.

index is equal to the actual number of the current layer. So, depending on what layer your expression is on, the value of index will vary. If you are in layer 1, index will be equal to "1", in layer 2 index will be equal to the number 2.

So, how do we use this? Here's a great example.

Create a solid that is 50x50 and make it a 3d layer.

On the position of the solid we just created, place this expression:

z = index * 20; [320 , 240 , z ]

We are setting the variable "z" to be equal to the index of the layer times 20. Notice the semicolon at the end. ANY time we are using a calculation with a variable, we MUST put a semicolon at the end, otherwise you will get an error.

The next line:

[ 320 , 240 , z ]

...positions the solid at 320 in the X and 240 in the Y. But, it's Z position is now dependent on the layer number. Try selecting the solid, and hitting "duplicate" several times (command/control-D). You'll see that each copy positions itself in a different spot in z space.

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.

32 Comments:

Blogger pablo said...

I've got a little late here, as I can see by the post date. But is so useful!! I am reading everything since the first lesson. Eager to see it until the end.

thanks a lot! great initiative.

5:51 AM  
Blogger Daniel said...

This comment has been removed by a blog administrator.

9:46 PM  
Blogger Kyle said...

Poor Daniel. I guess he can't read. How sad for him.

2:56 PM  
Blogger MaxofMO said...

Rufus Xavier Sassparilla!! You gotta love a guy who uses a School House Rock reference.

5:15 AM  
Blogger miss zelka said...

hey your awesome train drawing is missing ;)

can you please relink??

5:33 PM  
Blogger John said...

image not disponible (error)

8:26 AM  
Blogger Ruthie said...

Hey, I know this is an old blog, and I know the stuff you're posting is baby stuff for people who are trying to program in After Effects, but I just wanted to say thanks. I go to an art school for animation and for some reason they don't believe in teaching us useful things like learning how to use programs. Oh well! Thanks for this, it's written very clearly and has helped me a lot.

8:14 PM  
Blogger Alom said...

Hey,
Quick question: do effects in the layer effects panel have index values? If so, how can i get this value and then use it?

11:15 AM  
Blogger Anthony Fedor said...

From your post I could understand that you have well idea. You have to try to add more creativeness in your post. It will soon attract any reader. There are some different types of writing technique such as style, design, format.If you include all these styles you can make your blog more attractively.
Visit : Best thesis writing service .

2:37 AM  
Blogger William Gomez said...


download this app on an Android phone: Official vidmateapp

2:22 AM  
Blogger Maryum Ayub said...

Download best streaming application ShowBox

5:20 AM  
Blogger Sono Adney said...

Install free online Cinema Box Android and see your favourite videos.

6:32 AM  
Blogger Harish Raju said...

This blog explains the details about changing the ways of doing that business. That is understand well and doing some different process. Provides he best output of others. Thanks for this blog.
Web Designing Training in Chennai

12:46 AM  
Blogger Sono Adney said...

enjoy free videos online with Cinema Box Free App

12:10 PM  
Blogger Syed said...

Stickman Football
Androdumpper.net

7:44 AM  
Blogger dipdazzle said...

Vidmate App Latest Version Download:: Vidmate App Download

11:52 PM  
Blogger rahul chauhan said...

Happy Diwali Wishes Finally the much awaited festival Deepavali 2016 has come in this month which known as Diwali festival celebrated by everyone across the INDIA as well other countries Like : Nepal,USA,Cananda etc.

8:41 AM  
Blogger rahul chauhan said...

Thanksgiving day the beautiful and colorful parade of big balloons, charming cheerleaders, jokers, clowns, marching parade, the performance by celebrities is the best event that one could look up to in November 2016.thanksgiving quotes 2016

2:42 AM  
Blogger rahul chauhan said...

Thanksgiving day the beautiful and colorful parade of big balloons, charming cheerleaders, jokers, clowns, marching parade, the performance by celebrities is the best event that one could look up to in November 2016.thanksgiving 2016

9:20 AM  
Blogger Neil Jakson said...

Your blog is so interesting and thought provoking that I could not refrain myself from sharing it with others. Keep it up!
Dissertation writing services

10:57 PM  
Blogger anil kumar said...

Indian Biggest upcoming bahubali part 2 movie

Upcoming blockbuster Fast and Furious 8 Movie updates

Deepika Padukone Oops Moment

9:38 AM  
Blogger uday singh said...

This article was unique and interesting as it was very well described.Thanks for the information.

11:04 PM  
Blogger cm punk said...

Great post containing some tricky information about Opacity.thanks for sharing with us.
http://www.popdust.com/how-to-play-your-favorite-android-games-fully-2284617828.html

10:49 PM  
Blogger uday singh said...

awesome blog.it has explained us about different ways to do successful business.thanks for sharing.its really helpful.
http://socialnomics.net/2017/03/01/business-apps-and-tools-to-boost-productivity-of-your-startup/

7:06 PM  
Blogger Vijay Sinha said...

Amazing!!! I liked this blog so much it's really awesome I liked your creativity your way. I have also gone through your other posts too and they are also very much appreciate able and I have got some sweet comments for them also now I'm just waiting for your next update to come as I like all your other posts... well I have also made a video of my art hope you go through it on my channel your feedback is important subscribe if you like. holi , happy holi , Bollywood 2017 , . hot deepika padukone

2:35 AM  
Blogger Albert Smith said...

The information on the micro milling tool techniques have been an important source of reference while I was writing my machining workshop report and I am very grateful to have landed on this website. I am looking forward to reading more interesting and educational articles from this blog. Check out our professional writing services by clicking on Qualified Analysts.

6:53 AM  
Blogger Congtinh9x.tnjfjd Nguyen said...

The VidMate app for samsung allows you to stream and download videos from a variety of sources, such as YouTube, Dailymotion, Vimeo, and Yodesi.

9:56 PM  
Blogger anil kumar said...

Salman Khan Upcoming Biggest Blockbuster Movie Tiger Zinda Hai On this EID Tiger Zinda Hai

10:27 AM  
Blogger Aurora said...

This post gives intense detailing of array and variables. You have presented this idea in a good manner. Thank you so much...Admission essay writing service

11:12 PM  
Blogger bill mogan said...

tubemate for android 4.2 2 - is a free downloader for youtube videos

7:55 PM  
Blogger Roxy Chan said...

Vidmate App is very easy to use. Start Downloading now.

8:32 AM  
Blogger Handsome Boy said...

As with every other written piece, there are ways to secure that your blog post is of premium quality. Since writing compelling, high quality content is the only way to have a go at a blog salary, you must be very particular about such detail. You should keep it in mind whenever you are starting to make a post.
buy a research paper for college

3:10 AM  

Post a Comment

<< Home