ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

FAQ   •   VIEW ALL
 run expression every 2 frames.. every 3 frames etc? on Oct 1, 2008 at 6:14:43 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

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 1, 2008 at 6:21:23 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.

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 1, 2008 at 6:22:30 pm

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

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 1, 2008 at 6:27:50 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

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 1, 2008 at 7:59:51 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

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 23, 2008 at 12:46:43 pm

Is there a way to interpolate this "fake" keyframes ?

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

 Re: run expression every 2 frames.. every 3 frames etc?on Oct 23, 2008 at 3:12:01 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

 Re: run expression every 2 frames.. every 3 frames etc?on Dec 14, 2016 at 12:28:54 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) ```

 Re: run expression every 2 frames.. every 3 frames etc?on Dec 14, 2016 at 12:37:31 am

One way:

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

Dan