ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Limiting index-driven values within range, and looping the overflow.

FAQ   •   VIEW ALL
 Limiting index-driven values within range, and looping the overflow. on Feb 10, 2017 at 8:24:55 pm

Hey all, trying to make a grid system using a bunch of 120px square shape layers. The x position is governed by the layer index. I was wondering how I'd be able to force the x positions to fall between -900 and 900, so that a value of 1020 would return -900, and 1140 would return -780 and so on.

Ideally, each cycle would output a value that can be used to affect the Y position. But my priority is figuring out the X position.

I vaguely recall seeing an expression that fit the bill, long ago, but "loop" and "cycle" aren't the best search terms.

```x =-900+120*(index-1); y = value[1]; [x,y]```

 Return to posts index

 Re: Limiting index-driven values within range, and looping the overflow.on Feb 10, 2017 at 11:43:13 pm

Figured it out. Just used the modulus operator (%). Used the ratio of the base x value and the cycled x value to determine the y.

```xbase = 60+120*(index-1); x =60+120*(index-1)%1920; y = 60+((xbase-x)/1920)*120; [x,y]```

 Return to posts index

© 2017 CreativeCOW.net All Rights Reserved
[TOP]