Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Y position oscillates between numbers with holds

  • Dan Ebberts

    February 22, 2022 at 10:04 pm

    I’m not sure if this is what you’re after, but it might give you some ideas. Apply the expression to a layer’s position property and look at the result in the graph editor.

    minHold = .25;

    maxHold = 1.5;

    rampTime = .2;

    rampAmount = 100;

    t = tPrev = 0;

    while (t <= time){

    seedRandom(t,true);

    hold = random(minHold,maxHold);

    period = rampTime*2 + hold;

    tPrev = t;

    t += period

    }

    deltaT = time - tPrev;

    if (deltaT < rampTime)

    y = linear(deltaT,0,rampTime,0,rampAmount)

    else

    y = linear(deltaT,rampTime,2*rampTime,rampAmount,0);

    value + [0,y]

  • Jason Jantzen

    February 23, 2022 at 8:25 pm

    That works perfectly! I can adjust the rampTime to create a more triangle wave look or turn it way down to get a more square wave. Thanks again, Dan! Screenshot shows designer artwork under the animated emitter with your expression added to the emitter’s position property.

  • Jason Jantzen

    February 23, 2022 at 8:54 pm

    One thing I noticed is the Y position height is constant. Is there a way to randomize the rampValue to achieve a different height each time and maintain the triangle shape? I tried to add a wiggle to the value, but not only does it change the heigh but also the shape.

  • Dan Ebberts

    February 23, 2022 at 11:57 pm

    Try this:

    minHold = .25;

    maxHold = 1.5;

    rampTime = .2;

    rampAmount = 100;

    minRampMult = .75;

    maxRampMult = 1.25;

    t = tPrev = 0;

    rt = rampTime;

    ra = rampAmount;

    while (t <= time){

    seedRandom(t,true);

    hold = random(minHold,maxHold);

    rampMult = random(minRampMult,maxRampMult);

    rtPrev = rt;

    raPrev = ra;

    rt = rampTime*rampMult;

    ra = rampAmount*rampMult;

    period = rt*2 + hold;

    tPrev = t;

    t += period

    }

    deltaT = time - tPrev;

    if (deltaT < rtPrev)

    y = linear(deltaT,0,rtPrev,0,raPrev)

    else

    y = linear(deltaT,rtPrev,2*rtPrev,raPrev,0);

    value + [0,y]

  • Jason Jantzen

    February 24, 2022 at 9:58 pm

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