I would like an expression to randomly affect the position of a layer on a grid, like the example on Dan Ebberts website (Mastering Expressions, Pushing The Limits: Random Motion). However, instead of moving along a path from point A to point B, I would like the layer to jump from point A to point B (with no path in between) over 1 frame. The layer would then hold on that grid space for 5-10 frames before jumping to another grid space, and so on.
Having the ability to control the number of layers on the grid by way of a slider would also be very useful.
You are talking about a complex expression. The challenge is to randomly position a layer in the comp space, randomly change the time that each layer was in it's new position, and then make sure that two layers don't end up in the same position at the same time.
I've got a couple of animation presets that will arrange layers in a grid. First you need a layer named DL controller. This should be a null or a guide layer because it does not render. You apply this animation preset to the DL controller layer: Dropbox - Distribute layers-DL controller.ffx
This adds some sliders to the controller layer.
Next you create some slave layers. These can be any size but they should all be the same scale. These layers can be anything from text to shape layers to nested comps. Add the slave layers and apply this animation preset: Dropbox - Distribute layers slaves.ffx
This will give you this expression:
// Find Layer Size and calculate new size if scaled
Now comes the fun part. Position the controller (must be at the bottom of the stack) and the first slave layer follows. Scale the first slave layer to get the size you want, then start duplicating the layer and you get as many columns as you want starting from the position of the DL controller layer.
So with that as a starting point let's take a look at the expression and see what it does:
The first section just checks to make sure that you have at least one layer. The second section is where things get interesting. The "cp" is the current position of the controller so that starts distributing the layers. The column "col" function uses the index of the layer to adjust the position based on the width of the layer. When the number of columns is reached then a new row is started.
Here's what you could do. You could replace the "col" variable with a value at time function and maybe throw in a random generator. You could add a slider for number of cells in the grid to add a maximum value for the random column value you were trying to achieve. Say you wanted 10 columns and 5 rows, the number of cells would then be 50.
I haven't got time to mess around with it right now but that should get you started. I think it would be something like this:
cells = Math.round(random(1, 20)); // new variable to set the total number of cells in the grid
This is going to give you a maximum of 20 cells. You could replace the 20 with a slider value. I will have to think about how you would go about using the "time" method to change the time between the random numbers. There is probably a clue in Dan's grid expression.
There is more than one way to do this. Maybe the easiest thing to do would be pre-compose the layers then apply some time remapping. You would need to set Preserve Frame Rate when nested in the Pre-comp's Advanced Settings.