ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Simple Postion Random Expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Avrohom Kohn
Simple Postion Random Expression
on Dec 30, 2008 at 8:21:50 pm

I know this is a silly question, but I couldn't find the answer. I need to add a random position value (static) to a 3D layer, but I only want to randomize the x & z values, and I also want to limit where it goes. For example, I want a random z value between 0 and 1500, etc. & The same for the x...

Thanks.


Return to posts index

Dan Ebberts
Re: Simple Postion Random Expression
on Dec 30, 2008 at 8:50:06 pm

Something like this:

seedRandom(index,true);
x = random(0,1500);
z = random(0,1500);
[x,value[1],z]


Dan



Return to posts index

Avrohom Kohn
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:13:07 pm

Thanks. That works. Could you just explain what this is for:

seedRandom(index,true);

Why couldn't I just put in everything after that? I'm just trying to learn expressions and not just copy and paste every time.

Thanks.

Avrohom


Return to posts index


Avrohom Kohn
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:14:54 pm

And one more thing:

Every time I duplicate the layer, even the original randomizes again. Why doesn't it stay at the position it already chose.

thanks.

Avrohom


Return to posts index

Dan Ebberts
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:31:26 pm

Try using a constant for the seed rather than the layer index, like this:

seedRandom(1,true);


Dan



Return to posts index

Avrohom Kohn
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:39:26 pm

This last thing you mentioned (seedRandom(1,true); ) works much better. I didn't see it before. Sorry.

I was playing around with different numbers instead of 1. 10 gives me better results. Could you just explain what it's doing (what's the random index of the layer, and what's this number telling it)?

Thanks.

Avrohom


Return to posts index


Dan Ebberts
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:57:48 pm

The seed value of SeedRandom() just sets the starting point for the sequence of random numbers that get generated in the expression. You can stick any number you want in there to get different results. index is just the layer number (the index of the top layer is 1, etc.) and it's just a convenient thing to use as a seed because it's different for each layer. However, as you've seen, using the same seed for each layer generates different results for each layer anyway.

Dan



Return to posts index

Tom Granberg
Re: Simple Postion Random Expression
on May 14, 2010 at 4:24:19 pm

Is there a way to force the random numbers to certain increments?
Let's say, always pick numbers that are 10 apart.
So you end up with position changes that looks random but in a pre-defined grid increments?

Thanks.



Return to posts index

Dan Ebberts
Re: Simple Postion Random Expression
on May 14, 2010 at 4:41:53 pm

Sure - something like this should work (not tested):


numberOfXPositions = 40;
numberOfYPositions = 30;
disctanceApart = 10;
x = Math.floor(random(numberOfXPositions))*distanceApart;
y = Math.floor(random(numberOfYPositions))*distanceApart;
[x,y]



Return to posts index


Tom Granberg
Re: Simple Postion Random Expression
on May 14, 2010 at 5:14:31 pm

Great, here is a variation on the expression to lock one of the axis, as well as control the time interval the position changes.
To precisely control where the axis position is, I used (+b) I am sure some guru on here will figure out a much better way, but I like it:-)

Thanks to Dan!

holdTime = .5; //time to hold each position (seconds)
seed = Math.floor(time/holdTime);
seedRandom(seed,true);

numberOfXPositions = 1;
numberOfYPositions = 30;

a = 10; //fixed number value
b = 512; //fixed number value

x = Math.floor(random(numberOfXPositions))+b;
y = Math.floor(random(numberOfYPositions))*a;
[x,y]


Return to posts index

Dan Ebberts
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:28:16 pm

Try it - you can't break anything. :-)

What will happen is that the random position will change on every frame. seedRandom(seed,true) causes the same random numbers to be generated on each frame.

Dan



Return to posts index

Avrohom Kohn
Re: Simple Postion Random Expression
on Dec 30, 2008 at 9:35:45 pm

Ok. I was playing around with it. The problem is, the layers seem to be staying close to each other. I have 2 layers, they're nicely spaced. When I duplicate layer 2, both layer 3 and layer 2 are rerandomized, and mose times they stick dangerously close to each other and sometimes close to the first layer as well. Is there a way to control the amount of randomness?

Avrohom


Return to posts index


shawn baden
Re: Simple Postion Random Expression
on Jan 4, 2018 at 8:27:40 pm

I'm trying to get a random number between 1 and length of text - I have this working. It gives me a random number for every frame. I only want it to find a random number once and keep the value. I've tried using seedRandom but it isn't behaving the way I would expect. It gives me roughly half the value of the text length every time rather than from 1-10.

max = thisComp.layer("myLayer").text.sourceTextlength + 1;

seedRandom(1, true);
Math.floor(random(1, max));


Return to posts index

Dan Ebberts
Re: Simple Postion Random Expression
on Jan 4, 2018 at 9:09:30 pm

Did you try changing the seed to something else? What's your sample size? random can look not-too-random until you have a lot of instances.

Dan



Return to posts index

shawn baden
Re: Simple Postion Random Expression
on Jan 4, 2018 at 10:51:16 pm

I've tried changing the thread to 0, 1, 5... I'm changing the value of the sourceText from 4 letters to 15 letters and it's doing the same thing.


Return to posts index


shawn baden
Re: Simple Postion Random Expression
on Jan 5, 2018 at 2:28:18 am

I've realized that it is pulling the value at frame 0 every time I change the length of my text string. In addition it creates the same "random" sequence of numbers for each string length. A string character count of 14 always starts with 7. The only way around this that I can think of is to randomly choose a frame in the sequence to pull the value from. This I'm guessing will just run into the same random() problems.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]