creating a stylized tornado using expressions
In this tutorial, we will learn how to use expressions to create a tweakable tornado like effect. This effect might be easier to create using a 3d particle system like Trapcode's particular, or inside of a 3d package, but when I first wrote this expression, the only tool i had at my disposal was After Effects. I first created this expression when I needed to create some stylized bubbles spinning in a beaker for a chemistry video, but since then I have realized this technique has many more uses. Here is an example of the type of effect we can achieve:
Alright, I'm going to go pretty quick through the basics, and assume you are fairly familiar with After Effects. First, we will create a precomp that will represent the particle we will use in our tornado. Create a new comp, name it something like particle precomp and make it fairly small (I made mine 50 x 50 square pixels ). Create a comp sized solid and apply a circular mask, and adjust the Mask Feather property of the mask until you have a look that you like. Don't worry about the color of the solid for now, we will do something about that later.
Next, create another new comp, which will be your main comp with the tornado inside. Use the comp settings that match up with whatever format yuo intend to render to. I used an NTSC D1 preset. Inside this comp, create a null layer named Controls. Add a Color Control to this layer by going to Effect > Expression Controls > Color Control. Rename this color control particle_color. Keyframe this color control so that it includes the range of colors you want the particles in your tornado to be. I keyframed mine like this:

Once we create our tornado, each particle will choose a color from a random spot along the gradient created by this color control.
Next, add the particle precomp comp we made earlier to your current comp. Add the Fill effect to particle_precomp. This effect can be found in Effect > Generate > Fill. Add the following expression for the Color parameter of the Fill effect:
possibleColors =
thisComp.layer("Controls").effect("particle_color")("Color");
seedRandom( index , true );
sampleTime = random( 0 , thisComp.duration );
possibleColors.valueAtTime( sampleTime )
This expression is pretty simple. All it is doing is looking at the particle_color color control we created earlier, and choosing a random color from the gradient we created, and filling the particle with this color.
Now it is time to create the actual tornado. First, add 7 Slider Controls to the Controls layer by going to Effect > Expression Controls > Slider Control. Name the slider controls as follows: tornado_height, tornado_upper_radius, tornado_lower_radius, tornado_max_spin_speed, and tornado_min_spin_speed. Once this is done, your effect controls palette for your Controls layer should look like this:

Now add the following expression to the position parameter for your particle layer that we added earlier.
controlsPos
=
thisComp.layer("Controls").position;
tornadoHeight =
thisComp.layer("Controls").effect("tornado_height")("Slider");
upperRadius =
thisComp.layer("Controls").effect("tornado_upper_radius")("Slider");
lowerRadius =
thisComp.layer("Controls").effect("tornado_lower_radius")("Slider");
maxSpinSpeed =
thisComp.layer("Controls").effect("tornado_max_spin_speed")("Slider");
minSpinSpeed =
thisComp.layer("Controls").effect("tornado_min_spin_speed")("Slider");
//--
seedRandom( index , true );
bottomOfTornado = tornadoHeight/2 + controlsPos[1];
topOfTornado = -tornadoHeight/2 + controlsPos[1];
y = random( bottomOfTornado , topOfTornado );
radius = ease( y , topOfTornado , bottomOfTornado ,upperRadius ,
lowerRadius );
spinSpeed = random( minSpinSpeed , maxSpinSpeed );
angleStart = random( 0 , 2 * Math.PI );
x = radius * Math.cos( time * spinSpeed + angleStart ) +
controlsPos[0];
z = radius * Math.sin( time * spinSpeed + angleStart ) +
controlsPos[2];
//--
[x , y , z]

Now we will walk through this expression and dissect what each line means.
Lines 1 - 6 are just pick whip references to the slider control effects that are on our Controls layer. The statement that is not self explanatory in lines 1 - 6 is the first line. here we are creating a variable called controlsPos which we can refer to later. This way, when you move the Controls layer, the entire tornado moves with it and stays centered around it.
Lines 9 - 11 are fairly simple. Lines 9 and 10 simply define two variables topOfTornado, and bottomOfTornado which are the y values at which the tornado should cutoff. Line 11 simply chooses a random value, that is between the top of the tornado and the bottom of the tornado, which will be the y value of the particle for the whole animation.
Line 12 uses the ease() interpolation method. On this line we are determining the radius of the circle on which the particle should spin, based on the y position of the particle which we randomly generated on line 11. Essentially, this statement says "as the y variable goes from topOfTornado, to bottomOfTornado, have the variable radius go from upperRadius, to lowerRadius, using ease interpolation.
Lines 13-16 are where things start to get complicated. Line 13 is just choosing a random speed for the particle to spin at. Line 14 is just creating a variable named angleStart which is randomly chosen betwen zero radians and two pi radians. This just means that each particle will start at any a random angle around the imaginary circle it moves on. Lines 15 and 16 will be tough to understand if you don't know basic trig. These 2 lines are the ones that make the particle spin. If you know what polar coordinates are, you can think of these 2 lines as using the polar equation for a circle to make each particle revolve in a circle.
Well this sure looks cool, but how can we make it look better. We could try randomizing the scale or opacity of each particle. Also we could try to have the particles move slightly i the y direction. While I'm not going to walk you through it here, inside of the .aep below I have an example in which I used the noise() function to have each particle undulate randomly in the y direction during the tornado animation. This gives the animation as a whole a more organic feel. Download the After Effects 7.0 Project File here