Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Sincronize randoms for time, scale and position

  • Sincronize randoms for time, scale and position

    Posted by Mala Adolescenza on November 26, 2015 at 9:33 pm

    Hi, i’m new to AE expressions, I’m trying to make a video that jump cuts in time randomly while, at the same time, it changes position and scale (with the same random value of the jump cut).

    I’m working with this code for the time (taken by the forum):

    minDuration = 0.3;
    maxDuration = 0.9;
    minVal = inPoint;
    maxVal = outPoint - maxDuration;

    tEnd = 0;
    n = 0;
    seedRandom(n, true);
    preRun = random(maxDuration);
    while (time + preRun >= tEnd){
    n++;
    seedRandom(n, true);
    dur = random(minDuration, maxDuration);
    tEnd += dur;
    }
    t = time + preRun - (tEnd - dur);
    n += 9973;
    seedRandom(n, true);
    startVal = random(minVal, maxVal);
    linear(t, 0, dur, startVal, startVal + dur);

    I want it to jump cut, reposition and rescale to evitate black spaces, all simultaniously.
    I think the thing I must use is like seedRandom? I red about using Control Cursor etc… I really don’t know.

    Sorry for my english and thanks for your time.

    Mala Adolescenza replied 10 years, 10 months ago 3 Members · 4 Replies
  • 4 Replies
  • Kalleheikki Kannisto

    November 27, 2015 at 8:49 am

    There are (at least) three ways to syncronize random values.

    The first one is to use the same random seed for different effects. This works as long as you call the random number the same number of times and frequency for all effects.

    Another one is to use a random value in one location and then use expressions (or pickwhip) to read and modify that value.

    The easiest approach in many cases it to use a single slider control with wiggle expression and then link several effects to it. Might not apply in this case.

    —

    Looking briefly over the code, the StartVal is probably the one you want to base the other effects on. That is one that changes for every cut but remains fixed through a single clip (StartVal = the beginning time of the clip). That being the case, you could use the StartVal as your random seed, as it would force the random number to be the same throughout the clip (between cuts). Here’s where it gets interesting: You’ll have to copy the entire code that generates the StartVal for any effect you want to use it for. You can’t have one effect reading the StartVal from another effect. Which is why it is preferable to attach the code that generates the StartVal to a Slider Control, as you only have to do it once, and you can pick whip the value of the slider to other effects.

    —

    This can sound pretty complex if you’re new to expressions…

  • Kalleheikki Kannisto

    November 27, 2015 at 8:54 am

    In essence, what I am suggesting is that you copy all but the last line of this code to a Slider Control value expression, which should make the Slider Control value equal the StartVal. Then pickwhip that Slider value to the position and scale expressions and use some additional math to offset and scale them.

    Hopefully that works as anticipated.

  • Dan Ebberts

    November 27, 2015 at 10:01 pm

    The trick is to calculate the random timing in one place, and “publish” it for the other properties to use as random seeds. This generally requires two pieces of information, so you can apply a Point Control to the layer with an expression like this:

    minDuration = 0.3;
    maxDuration = 0.9;
    minVal = inPoint;
    maxVal = outPoint – maxDuration;

    n = 0;
    seedRandom(index, true);
    preRun = random(maxDuration);
    tEnd = -preRun;
    while (time > tEnd){
    n++;
    seedRandom(n, true);
    dur = random(minDuration, maxDuration);
    tStart = tEnd
    tEnd += dur;
    }
    [tStart,tEnd]

    Then you can use expressions like this on the properties where you want to sync the randomization:

    // uniform scale

    ptCtrl = effect(“Point Control”)(“Point”);
    tStart = ptCtrl[0];
    tEnd = ptCtrl[1];
    minVal = 50;
    maxVal = 200;
    seedRandom(tStart,true);
    startVal = random(minVal,maxVal);
    seedRandom(tEnd,true);
    endVal = random(minVal,maxVal);
    s = linear(time,tStart,tEnd,startVal,endVal);
    [s,s]

    // non-uniform scale

    ptCtrl = effect(“Point Control”)(“Point”);
    tStart = ptCtrl[0];
    tEnd = ptCtrl[1];
    minVal = [50,50];
    maxVal = [200,200];
    seedRandom(tStart,true);
    startVal = random(minVal,maxVal);
    seedRandom(tEnd,true);
    endVal = random(minVal,maxVal);
    linear(time,tStart,tEnd,startVal,endVal);

    // rotation

    ptCtrl = effect(“Point Control”)(“Point”);
    tStart = ptCtrl[0];
    tEnd = ptCtrl[1];
    minVal = -360;
    maxVal = 360;
    seedRandom(tStart,true);
    startVal = random(minVal,maxVal);
    seedRandom(tEnd,true);
    endVal = random(minVal,maxVal);
    linear(time,tStart,tEnd,startVal,endVal);

    // position

    ptCtrl = effect(“Point Control”)(“Point”);
    tStart = ptCtrl[0];
    tEnd = ptCtrl[1];
    minVal = [width,height]/2;
    maxVal = [thisComp.width,thisComp.height] – minVal;
    seedRandom(tStart,true);
    startVal = random(minVal,maxVal);
    seedRandom(tEnd,true);
    endVal = random(minVal,maxVal);
    linear(time,tStart,tEnd,startVal,endVal);

    // opacity

    ptCtrl = effect(“Point Control”)(“Point”);
    tStart = ptCtrl[0];
    tEnd = ptCtrl[1];
    minVal = 25;
    maxVal = 100;
    seedRandom(tStart,true);
    startVal = random(minVal,maxVal);
    seedRandom(tEnd,true);
    endVal = random(minVal,maxVal);
    linear(time,tStart,tEnd,startVal,endVal);

    Generally (except for uniform scale) you just need to update minVal and maxVal to fit the property.

    Dan

  • Mala Adolescenza

    November 28, 2015 at 6:13 am

    First thing, I’ll like to thank both of you.

    Second, I’ve gone with Kalle solution ’cause is more step-by-step and I’m new to AE expressions but there are some problems, triying to apply that expression to Cursor results in “expression result must be of dimension 2, not 1, error occured at line 0”. While, not changing my original working Cursor expression that was:

    minDuration = 0.3;
    maxDuration = 0.9;
    minVal = inPoint;
    maxVal = outPoint - maxDuration;

    tEnd = 0;
    n = 0;
    seedRandom(n, true);
    preRun = random(maxDuration);
    while (time + preRun >= tEnd){
    n++;
    seedRandom(n, true);
    dur = random(minDuration, maxDuration);
    tEnd += dur;
    }
    t = time + preRun - (tEnd - dur);
    n += 9973;
    seedRandom(n, true);
    startVal = random(minVal, maxVal);

    and using the others expression you suggested, in particular for uniform scale and position, they result in “index 1 out of range, expression disabled”.

    Thanks again for your time,
    bye.

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