Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions random starting position

  • random starting position

    Posted by Matthew Tully on February 5, 2008 at 9:13 pm

    howdy all,

    i am looking for a way to randomly assign a layer’s position each time a project is rendered.

    ideally i would set 4 predetermined positions, then the random seed would pick one of the starting places. i am imagining some sort of “if / then” statement.

    i am looking into Dan’s Motionscript articles on random(), but i am having trouble bridging the gap.

    please help.

    Darby Edelen replied 18 years, 3 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    February 6, 2008 at 6:11 am

    You might be able to do it with a simple script, but more info about your work flow would be helpful.

    Dan

  • Matthew Tully

    February 6, 2008 at 6:53 pm

    Hi Dan,

    Thanks for having a look, maybe I can explain the scenario in a hypothetical example:

    I have a project with one comp and in the one comp I have one solid.

    I am trying to have the starting position (frame 1) of this solid randomly selected from one of 4 possible selections (array or if/then?) out of the frame.

    Then I would like to have the solid move to the center of the comp over time, either controlled in the expression or with keyframes.

    Each time I render this comp I would like it to randomly choose a starting position from one of the 4 choices. This part is important.

    So that’s my idea in a nutshell. So far I am only able to pass off a random number of either 1,2,3, or 4, and then assign an “if / then” to the position of the solid. However this is not a true random variable. Each time I render it, it always picks the same starting random seed.

  • Darby Edelen

    February 6, 2008 at 9:16 pm

    I believe that you would need to have access to some data in your expression that would change every time you render and use that as the seed. Unfortunately, expressions don’t have access to that kind of data. As Dan suggests, you might need a script to accomplish this.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Matthew Tully

    February 6, 2008 at 9:42 pm

    could seedRandom pull just one value from one random frame each time the comp was rendered.

    i’m surprised there is no real way to generate a random variables. This seems like a really primitive function.

    so if it must be a script, can anyone point me in the proper direction there? please don’t let this one drift away.

  • Dan Ebberts

    February 7, 2008 at 12:27 am

    OK – suppose you have a layer (a null maybe) with a point control applied (Effect > Expression Controls > Point Control). You could select that layer and run a script like this (copy it and save it somewhere with a .jsx extension):

    var points = [[0,0], [100,0], [100,100], [0,100]];
    var idx = Math.floor((Math.random()*points.length));
    var myLayer = app.project.activeItem.selectedLayers[0];
    var myPointCtrl = myLayer.property(“ADBE Effect Parade”).property(“ADBE Point Control”);
    var myProp = myPointCtrl.property(“ADBE Point Control-0001”);
    myProp.setValue(points[idx]);

    This should randomly populate the point control with one of the four points defined in the first line of the script. Then you could link the position of the layer you want to move randomly to the point control via a simple expression.

    Then you just need to run the script (File > Scripts > Run Script File…) each time before you render (although, if you’re only talking about 4 different positions, it might be easier to just do it by hand).

    Dan

  • Darby Edelen

    February 7, 2008 at 7:01 am

    [matthew tully] “could seedRandom pull just one value from one random frame each time the comp was rendered.

    i’m surprised there is no real way to generate a random variables. This seems like a really primitive function.”

    I thought I knew what you were trying to do, but now I’m a little confused.

    You do or you don’t want a random value on each frame of the animation?

    When you call seedRandom(x) the ‘x’ value determines the sequence of numbers you will receive when calling the random() function. So in order to change the sequence each time you render (or the first value if you don’t want a random value on each frame) the value of ‘x’ needs to be different each time you render which would either require you to access some variable that you cannot access through expressions (so that’s out) or manually adjust the ‘x’ value before each render.

    The easiest way I can think to modify the ‘x’ value would be to use the layer’s index as the random seed:

    seedRandom(index);

    And then create a Null at the top of the composition and duplicate the Null before each render (thus changing the index of your layer and the seed value).

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy