ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

A for loop inside an if statement inside a for loop = confusion

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Madison Bullard
A for loop inside an if statement inside a for loop = confusion
on May 20, 2014 at 4:33:08 pm
Last Edited By Madison Bullard on May 20, 2014 at 5:02:11 pm

I'm trying to set up an expression that will allow me to place a bunch of layers in a grid, like tiles across the frame. I want the edges of the layers to touch. I'm assuming that I'm working with a 16:9 frame and all the layers are also 16:9.

Apparently i'm going about this the wrong way, but I can't figure out why this expression isn't working. I'm sure it has to do with the fact that I'm not very confident with my Javascript skills.

Any suggestions?

*edit* The following expression gives me this:

The first row works fine, after that each "row" starts cascading diagonally, stacking on top of each other in groups of 5.
x=width*transform.scale[0]/200;
y=height*transform.scale[0]/200;
xOffset = 0;
yOffset = 0;
tilesPerRow = 5;

for (i=0; i<=tilesPerRow; i++){
if (thisLayer.index/tilesPerRow > i && thisLayer.index/tilesPerRow <= i+1){
for(j=i*tilesPerRow+1; j<thisLayer.index; j++){
xOffset += thisComp.layer(j).width*thisComp.layer(j).transform.scale[0]/100;
if (i>0){
yOffset += thisComp.layer(i).height*thisComp.layer(i).transform.scale[1]/100;
}
}
}
}

[x+xOffset,y+yOffset]


Return to posts index


Dan Ebberts
Re: A for loop inside an if statement inside a for loop = confusion
on May 20, 2014 at 5:30:49 pm

Assuming all layers are participating, I'd do something like this:

titlesPerRow = 5;
w = width*transform.scale[0]/100;
h = height*transform.scale[1]/100;
row = Math.floor((index-1)/titlesPerRow);
col = (index-1)%titlesPerRow;
[w,h]/2 + [col*w,row*h]


Dan



Return to posts index

Madison Bullard
Re: A for loop inside an if statement inside a for loop = confusion
on May 20, 2014 at 5:32:38 pm

haha wow that is WAY simpler (and it works too!). Thanks, Dan.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]