motion graphics eXchange

distributing layers in a cylinder using expressions

Thumbnail for: distributing layers in a cylinder using expressions
This expression is customizable, and you can change many things including: the radius of the cylinder, the overall rotation of the cylinder, the spacing vertical spacing between rows of the cylinder, and the amount of layer on each level of the cylinder.
After Effects 7
Useful things

Views: 5407
visit |  share this  error? 
First, create a new comp, and make sure to use square pixels. Non-square pixels can lead to some nasty issues with all the math going on in these expressions. Now, inside of your newly created comp, create a new Null Object, and name it Controls. Make this null object 3d, and position it properly, because once we create the cylinder, it will be centered around this null object. Now, you are going to add some expression controls to our null object, Controls. Expression controls are just "dummy effects" which have no impact on how the layer works. However, you can reference expression controls in an expression, and then use that value. Now, with your Null Object selected, go up to Effect > Expression controls, and add 3 Slider Controls to the layer, and one Angle Control. Now, we will rename these controls something useful. Open up the effect controls palette. Now, select you first slider control, and press Enter.

Now, name your 3 sliders height_gap, radius, and layers_per_level. Next, name your angle control cylinder_rotation. Once we have our expression, layers_per_level can be keyframed to change how many layers are in each level of the cylinder, radius can be keyframed to change the radius of the cylinder, and height gap can be keyframed to change the vertical gap between the layers. Before you continue, be sure to set layers_per_level to something positive, so it doesn't generate and error later on! Also, be sure to set layers_per_level to a whole number, so the cylinder will look even.

Alright, now for the good part. Create a solid, which you will want to be square if you are replicating the look of my example. Make the layer 3d. Now add the following expression for position:
controls = thisComp.layer("Controls");
layersPerLevel = controls.effect("layers_per_level")("Slider");// can't be negative or zero
heightGap = controls.effect("height_gap")("Slider"); //pixels
radius = controls.effect("radius")("Slider");//pixels
overallRot = controls.effect("cylinder_rotation")("Angle");
ind = index -1;
maxAngle =  360;
angleGap = maxAngle / layersPerLevel;
angle = ( angleGap * ind + overallRot ) % maxAngle;
x = radius * Math.cos( degreesToRadians( angle ) );
z = radius * Math.sin( degreesToRadians( angle ) );
y = Math.floor( ( angleGap * ind ) / maxAngle ) * (thisLayer.height + heightGap);
[x , y , z] + controls.position;
Now, add this expression for orientation in order to make your layer point towards the center of the cylinder.
controls = thisComp.layer("Controls");
deltaX = position[0] - controls.position[0];
deltaZ = position[2] - controls.position[2];
yAngle = Math.atan2( deltaX , deltaZ);
[value[0] , radiansToDegrees( yAngle ) , value[2]]
Now duplicate your layer, by pressing Ctrl + d (or Cmd + d), until you have the desired number of layers. There you have it, a nice cylinder. Feel free to keyframe any of the expression controls from earlier, just make sure not to have num_of_layers be negative or zero, otherwise it will generate an error. Note that in order to move the whole cylinder, simply animate the position of the Controlslayer. Also, be sure not to place any layers above or in between the layers that make up the cylinder, this will cause the expression to not work, as the results of the position expression are based on each layer's number in the timeline (called the layers index in expression terminology).


vertical spacing

(Min. Version: After Effects 7, Category: Useful things, Type: Expressions)
posted by MicGyver on Sep 08, 2008


Related topics:

Wiggle in one dimension

Thumbnail for: Wiggle in one dimension
Often very useful to wiggle only horizontal or vertical
After Effects 6
Useful things

Views: 36338
posted by jamie on Sep 05, 2008

Ascii animation with sampleImage()

Thumbnail for: Ascii animation with sampleImage()
More experimentation with sampleImage().
After Effects CS3
Useful things

Views: 5259
posted by mmo on Sep 02, 2008

3D Shadows (Video Copilot, No. 71)

Thumbnail for: 3D Shadows (Video Copilot, No. 71)
Cast 3D shadows onto live action footage
Use shadow diffusion and special material options
Tutorials for Visual Effects & Motion Graphics
Free After Effects Tutorials & More Hosted By: Andrew Kramer
After Effects CS3

Views: 7639
posted by MicGyver on Nov 11, 2008



follow us on in touch on facebook



Full length video training series presented by motion graphics industry professionals. Click here to visit Motionworks website!