I use After Effects CS6,

I need to add a lot of pictures inside my comp,

they need to have random position (if I could set the "range of the randomness" that would be great)

is there any way to do that ?

and I'm not looking at a wall image plugin (with these plugins, all pic are in the same plane, but I need randomness on the Z-axis too)

I'm trying to make something similar to the TV Show Person of Interest: how the AI has multiple image when "we" are inside "his mind". link to img

I have already done a big part of it manually, but it just takes too long to do it with new packs of images.



Dump all your images into your timeline. Select one and alt-click the stopwatch on the position property, to add an expression. You need to write a javascript expression that returns an array of 3 numbers that will randomly position the image within the comp. This will do it:

seedRandom(index, timeless = true);
var x = random(thisComp.width);
var y = random(thisComp.height);
var z = random(thisComp.width);
[x, y, z]

IF you right-click the position property and choose copy expression only, you can then paste it to all the other images in your comp and they will scatter to randomly fill a cube the size of your comp (and as deep on the z axis as the width of your comp).

How it works

(read this if you want to be able to hack it to your own needs)

The seedrandom function sets the random seed for the random number generator, and we give it two parameters, index meaning the layer number, and timeless=true. By using the layers' index to generate the random number, each layer will have a different set of coordinates. Timeless=true means that the random number doesn't change over time.

var x = Math.random(thisComp.width) sets the variable x to have a random value somewhere between 0 and the width of the comp. If you wanted this to be a different value you could type in a number instead of thisComp.width. All three variables are set the same way.

The last line puts them into an array, which is what the position property needs.

To refine it you might want to use the guassRandom function instead of random - that will mean the images will cluster towards the centre, like a galaxy. You could also create a null and add three slider effects to it (in effects>expression controls). You could use them to control the width, height and depth of the cloud. To do that select the bit inside the random function that says thisComp.width, delete it and with the cursor inside the brackets grab the pick-whip (the little spiral near the expression twirl down) and drag it to the slider effect control.

enter image description here

The result should be that the line will now look like:

var x = gaussRandom(thisComp.layer("Null 1").effect("Slider Control")("Slider"));

Do that for all three dimensions using a different slider for each and once again copy the expression to all the layers. Now you can control how far they spread with the sliders, and even animate it, by animating your sliders, so for example they could all spread out from the centre over time.

  • Thanks a LOT. This is perfect, I can do what I want with that (plus some tweak, but this is great already). I'll start learning Js asap.
    – DomSpiegel
    Sep 24 '16 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.