# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression for random, fixed position controlled by time?

• # Expression for random, fixed position controlled by time?

Posted by on May 4, 2005 at 8:48 am

Greetings!

Is there an expression that will place a layer at a random position (lets say +/-150 pixels max variance in both x and y from the center-position), it will stay locked in that position for the duration of the clip, but if I place the clip further down the timeline it will use a different random position? So if I had the clip appear at time 5:00 it would be in one position, but if I slid the clip down to time 5:01, it would be in a different random position.

Kind regards,
Eric

3 Members · 7 Replies
• 7 Replies
• ### Mylenium

May 4, 2005 at 9:54 am

Why don’t you just split your clip and then apply a simple expression like new_position=position+random(-150,150); ???

Mylenium

[Pour Myl

• ### Eric Steinberg

May 4, 2005 at 10:21 am

To answer your question: Because I don’t know expressions very well at all! 😉 But anyway, thank you so much, that does exactly what I need…almost. Your expression puts the item in a random position in the x-axis, but not in the y-axis. I thought I would be brave and try to write one that works in y also, so I wrote:

new_position=position+random[(-150,150),(-150,150)]

but that didn’t work. It actually made AE shut down!! So if you could help me with an expression that affects the position in x and y, I would be very grateful!

Kind regards,
Eric

• ### Mylenium

May 4, 2005 at 11:32 am

Mmh, AE should add the random value to both dimensions, but anyway, here’s the correct one:

X=position[0]+random(-150,150);
Y=position[1]+random(-150,150);

[X,Y]

Mylenium

[Pour Myl

• ### Eric Steinberg

May 4, 2005 at 12:28 pm

Thank you, now it is random in x and y. But I have to apologize, I didn’t check the first one properly, it actually doesn’t do what I want. I want the clip to stay in the same position once a random position is assigned. I’m sorry if I didn’t describe properly what I’m going for; I’ll try desribing it a little more clearly:

An expression that will make the position of the footage item be randomly offset by maximum 150 pixels (x and y), and for the whole duration of the clip it stays locked/fixed in the same position. I then want to duplicate that layer, replace footage in the duplicate, and move this new layer to a later point in time in the timeline. Now this new layer will also have a randomly offset position by maximum 150 pixels, but it is a different random position than the first layer. And this new layer’s position also stays locked for its duration. Then I want to be able to keep doing this: Duplicating layers, replacing footage, and sliding down the timeline the new layers, and each time they will have a different, fixed position.

Hope this makes sense.. :-}

Kind regards,
Eric

• ### Eric Steinberg

May 4, 2005 at 2:19 pm

Ok, after doing som reading on Dan Ebberts site ( https://www.motionscript.com ) and experimenting a little bit, I think I got it now!
By restricting the results of the calls to random to the values between 40% and 60% of the width and height of the comp,
this expression seems to do what I want:

minVal = [0.4*thisComp.width, 0.4*thisComp.height] ;
maxVal = [0.6*thisComp.width, 0.6*thisComp.height] ;

seedRandom(3,true) ;
random(minVal,maxVal)

I’ll play with it a little more to make sure, but I think this is it!
I appreciate your previous help, I just didn’t explain clearly enough what I needed.

Kind regards,
Eric

• ### Dan Ebberts

May 4, 2005 at 3:13 pm

I think this might be a simpler version of what you’re looking for:

seedRandom(index,true);
value + random([-150,-150],[150,150]);

Dan

• ### Eric Steinberg

May 4, 2005 at 3:36 pm

Indeed it is! Thank you so much 🙂

Kind regards,
Eric

We use anonymous cookies to give you the best experience we can.