Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › set initial x, y, and z with expression – subsequent frames hold frame 1 values

  • set initial x, y, and z with expression – subsequent frames hold frame 1 values

    Posted by David Ford on June 8, 2006 at 2:46 pm

    It seems afx re-runs expressions every frame without remembering previous frame’s variables values. How do you work around this?

    I would like to re-use the initial variables (x, y and z) set at frame 1, so that the position is not changing in subsequent frames. Code below.

    [code]
    if(time == 0){
    x = Math.floor(random(thisComp.width));
    y = Math.floor(random(thisComp.height));
    z = Math.floor(random(-300, 300));
    [x,y,z];
    } else{
    // of course this produces errors
    [x,y,z];
    }
    [/code]

    I’ve seen similar problems in other posts here, but can’t seem to work those into this scenario. If so, could you please send link?
    Thanks

    Mylenium replied 20 years, 3 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 8, 2006 at 3:13 pm

    Expressions execute at each frame and there is no way to pass data from one frame to the next. The work-arounds depend on what it is that you’re trying to do.

    If all you want to do is generate a static random position, you could do it this way:

    seedRandom(index,true);
    x = Math.floor(random(thisComp.width));
    y = Math.floor(random(thisComp.height));
    z = Math.floor(random(-300, 300));
    [x,y,z];

    Dan

  • David Ford

    June 8, 2006 at 3:31 pm

    Hi Dan,

    Thanks for the reply and the code!

    Guess you’ve said this a million times by now. I noticed in other forums you’ve answered this same question. Thanks for your patience!

    For some reason the code below causes the layer text to disappear after frame 1. Am I missing another step in using this correctly?
    Comp set up – 640×480 10 seconds

    seedRandom(index,true);
    x = Math.floor(random(thisComp.width));
    y = Math.floor(random(thisComp.height));
    z = Math.floor(random(-300, 300));
    [x,y,z];

  • Dan Ebberts

    June 8, 2006 at 3:37 pm

    I can’t repro the problem here. You have a text layer and you’ve applied the expression to the layer’s Position property, is that correct?

    Dan

  • David Ford

    June 8, 2006 at 3:43 pm

    Dan, thank you so much! I had another expression that was removing the text value. Works like a charm!

    I guess I would like to understand more about wha the seedRandom() method does. Is there any information on this anywhere? The help files are pretty sparse.

  • Mylenium

    June 8, 2006 at 6:00 pm

    [David Ford] “I guess I would like to understand more about wha the seedRandom() method does. Is there any information on this anywhere? The help files are pretty sparse.”

    seedRandom() assigns a continuous – erm – seed to random functions. Randomness in computers is not really random, it’s based on formulas. For instance a common method is Perlin Noise which itself is just a set of overlapping sinus/ cosinus functions with random phase and periods. If you calculate a time dependent sinus with Math.sin(time), your result is a wave. Multiple such overlapping functions with different multipliers (e.g. time*2) create pseudo-random peaks and grooves. By fixing the seed in random functions, you more or less freeze time – with the same input, the result is always the same.

    Mylenium

    [Pour Myl

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