FORUMS: list search recent posts

Expression syntax problems - FOR loop

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Alfred Timotei
Expression syntax problems - FOR loop
on Dec 3, 2016 at 4:37:04 pm
Last Edited By Alfred Timotei on Dec 3, 2016 at 4:39:12 pm

Hi guys, please help me with this code.
I'm beginner with coding and I'm sure I have made a mistake with the syntax.
I'm trying to find out with "c" variable how many pixels are from the end of the layer to the text itself, using sampleImage and moving the target point. I've tried to make a loop and for every pixel that have the sampleImage [0,0,0,0] result add 1 to counter c that had the initial value 0. Also, when the first pixel with no transparency is encountered I want the loop to break.

c=0;
for(x=1920;x==0;x--){
y=659;
t=thisComp.layer("Text 1");
r=t.sampleImage([x,y],[1,1]);
if(r==0) {c=c+1} else break;
};
c


Return to posts index

Dan Ebberts
Re: Expression syntax problems - FOR loop
on Dec 3, 2016 at 6:09:14 pm

Try it this way:


y = 659;
t=thisComp.layer("Text 1");
for(x=1920 ; x >= 0; x--){
r=t.sampleImage([x,y],[1,1]);
if(r[3] > 0)break;
}
x


Dan



Return to posts index

Alfred Timotei
Re: Expression syntax problems - FOR loop
on Dec 3, 2016 at 6:27:04 pm

Thank you very much Dan.
I sure didn't understand the FOR statement. I thought that the loop stops when the second parameter (condition) is accomplished, but now I think I understand it. Please correct me if I'm wrong. The loop stops when the condition is not correct anymore.


Return to posts index


Alfred Timotei
Re: Expression syntax problems - FOR loop
on Dec 3, 2016 at 6:57:25 pm

Hi again,

I've tried another thing. Depending on the last letter in the text layer, is possible that earlier expression doesn't see exactly the last pixel. I've set the y to be in the middle of the text row, but for example if I have the last letter an X, the result will not be correct. So I've used a for statement also for y. But my computer look like an x86 when the expression is running. Do you think there is a way to make the expression to use fewer resources?

x2=0;
t=thisComp.layer("Burtiera 1");
for(y= 640; y &lt;=680; y++){
for(x=1920; x >= 0; x--){
r=t.sampleImage([x,y],[1,1]);
if(r[3] > 0) break;
}
if(x>x2) x2=x;
}
x2


Return to posts index

Dan Ebberts
Re: Expression syntax problems - FOR loop
on Dec 3, 2016 at 11:13:09 pm

What version of AE are you running? It would be more efficient (and accurate) to use sourceRectAtTime() instead of sampleImage().

Dan



Return to posts index

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