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.

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:

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).