Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions run expression every 2 frames.. every 3 frames etc?

  • run expression every 2 frames.. every 3 frames etc?

    Posted by Sergio Juyak on October 1, 2008 at 6:14 pm
    
    

    I have a very simple expression for the position prop that makes a layer jump around:

    x = random(500, -500);
    y = random(500, -500);
    position + [x,y];

    This makes my layer jump around every frame really fast… i’d like the expression make my layer change positions more slowly, say, every 3 frames or 5 frames… is there a way i can have AE run the expression only once every 3 or 5 frames? If not is there an alternate method? I don’t think wiggle will work because this will “wiggle” the position… and i need “jumpy” or “blinky” movement… thanks

    Dagur Maunason replied 9 years, 4 months ago 5 Members · 9 Replies
  • 9 Replies
  • Eric Sanderson

    October 1, 2008 at 6:21 pm
    probability = 3;
    
    r = (random(-probability+2,1));   //determines how often it wiggles, 
    
    -4,1= 1/6th of the time with a clamp of 0,1
    
    v = clamp(r,0,1);
    
    s = wiggle(10, 400*v);
    
    x = value[0];
    
    y = s[1]; 
    
    [x,y]
    

    You can define variable probability using random and a clamp, heres an example that i did using text not to long ago…this code only wiggles on the Y.

  • Eric Sanderson

    October 1, 2008 at 6:22 pm

    …sorry, it copied weird…the 2nd and 3rd line shown there is actually all on one line.

  • Eric Sanderson

    October 1, 2008 at 6:27 pm
    probability = 3;
    r = (random(-probability+2,1));
    v = clamp(r,0,1):
    s = random(500,-500;
    x = s[0];
    y = s[1];
    position + [x,y]
    

    here is the code you would use pertaining to your project…let me know how it works

  • Dan Ebberts

    October 1, 2008 at 7:59 pm

    Something like this should make it change every three frames:

    period = 3; // frames
    posterizeTime(1/(period*thisComp.frameDuration));
    x = random(500, -500);
    y = random(500, -500);
    position + [x,y];

    Dan

  • Gianluca Belvisi

    October 23, 2008 at 12:46 pm

    Is there a way to interpolate this “fake” keyframes ?

    Check this out
    https://www.glbproject.it

  • Dan Ebberts

    October 23, 2008 at 3:12 pm

    Like this maybe:

    period = 3; // frames

    f = timeToFrames();
    seg = Math.floor(f/period);
    interp = time – framesToTime(seg*period);

    seedRandom(seg-1,true);
    prev = random([-500,-500],[500,500]);
    seedRandom(seg,true);
    next = random([-500,-500],[500,500]);
    value + linear(interp,0,framesToTime(period),prev,next)

    Dan

  • Dagur Maunason

    December 14, 2016 at 12:28 am

    I’ve been tweaking this expression to set opacity to 100 every 20th frame and then fade out again, repetively. It’s all working as I want exept that I can’t for the life of me get it to start the loop at the text layers inPoint. Anyone got an idea of how to achieve that?

    period = 20;

    f = timeToFrames();
    seg = Math.floor(f/period);
    interp = time - framesToTime(seg*period);

    minVal = 0;
    maxVal = 100;

    linear(interp,0,framesToTime(period),maxVal,minVal)

  • Dan Ebberts

    December 14, 2016 at 12:37 am

    One way:

    period = framesToTime(20);
    t = (time-inPoint)%period;
    minVal = 0;
    maxVal = 100;
    linear(t,0,period,maxVal,minVal)

    Dan

  • Dagur Maunason

    December 14, 2016 at 12:46 am

    Flawless! Thank you so much Dan 🙂

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