Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: HomeForumBasicsExpressionsTutorialsPodcastsMotion GraphicsTrainingCinema 4DFAQ

Make a linear Loop

Cow Forums : Adobe After Effects Expressions

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>
Make a linear Loop
by Claudio Franco on May 26, 2009 at 4:47:03 pm

I've a simple expression to make the opacity go from 0 to 100 like this:


linear(time,0,3,0,100)

and it work ok...

but i want to make this in loop like fadeIN and fadeOUT

i try something like this:

startVal = 0;
endVal = 100;

opa = linear(time,time,time+3,startVal,endVal)

if(opa==100)
{
startVal = 100;
endVal = 0;
}
else
{
startVal = 0;
endVal = 100;
}


But it doesnt work and i simply, can't figured out...

Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Eric Sanderson on May 26, 2009 at 4:56:33 pm

Im not sure how to alter your code to work but if its taking too much time to figure out i would just keyframe the fade up and back down over 3 seconds then "loopOut("cycle")" to get them to loop continuously.

Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Claudio Franco on May 26, 2009 at 4:49:55 pm

Thanks... i'm already using that, but i have to apply this for hundreds of objects, so i really want a "expression" solution... but thanks!

Respond to this post   •   Return to posts index


Re: Make a linear Loop
by Eric Sanderson on May 26, 2009 at 4:50:22 pm

It also looks to me like your just defining variables without actually executing them for anything, Your saying what startVal and end equals but not putting them to use, and actually giving the same variable different values. Im not an expression pro at all or anything so this could be a method im not aware of but thats the main problem i can see with the code.

Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Eric Sanderson on May 26, 2009 at 5:05:38 pm

you could also try this..

Math.abs(Math.sin(time)*100)


Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Koby Goldberg on May 26, 2009 at 5:46:19 pm

Eric's idea is really nice and simple.
If you want to change the time that the opacity rises from 0 to 100 to a specific duration value, use the following expression:

duration = 3;
Math.abs(Math.sin(time/duration*Math.PI)*100)


if you insist on linear opacity and not SIN opacity, you could use the next expression:

duration = 3;
T = Math.round(duration/thisComp.frameDuration);
t = Math.round(time/thisComp.frameDuration);
100*( 1 - Math.abs(t%(2*T) - T)/T )


Koby.

Respond to this post   •   Return to posts index


Re: Make a linear Loop
by Dan Ebberts on May 26, 2009 at 6:12:08 pm

Like this maybe:

period = 6;
t = time%period;
Math.min(ease(t,0,period/2,0,100),ease(t,period/2,period,100,0))


Dan



Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Koby Goldberg on May 26, 2009 at 7:58:33 pm

Or this

period = 3;
t = time;
50*(1 - Math.cos(t / period * Math.PI))

(which will yield almost the same result as Dan's expression, but i think will render faster :-) )


Koby.

Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Eric Sanderson on May 26, 2009 at 8:25:37 pm

Koby.

I was just curious as to the purpose of the "1-Math.cos"..doesnt that basically leave you with a Math.sin?

Respond to this post   •   Return to posts index


Re: Make a linear Loop
by Koby Goldberg on May 26, 2009 at 9:00:21 pm

Hi Eric,
No, this is not the same.
SIN(X) is also negative (in case piHowever (1-COS) is always positive.

p.s. you could check out the behaviour of the expression in the graph editor of AE (don't forget to press the small graph icon near the property name to see it in the graph editor)


Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Claudio Franco on May 27, 2009 at 8:37:57 am

This works, but i have to use linear function...

The thing is, i have for example 10 objects, i and want them to all to have the same effect, and that expression works.

But i want to 3 of them, to start the effect at time 1 sec
Other 3 to start at time 2sec
etc

To have a "effect" that they are all uncoordinated.

If i use your function, they will all have the opacity at 0 and 100 at the same time, because the your expression is all based in time.

Sorry, i know i didn't explained this at the beginning.

Respond to this post   •   Return to posts index

Re: Make a linear Loop
by Dan Ebberts on May 27, 2009 at 1:28:55 pm

Maybe like this:

period = 6;
delay = 1;
if (time > delay) {
t = (time-delay)%period;
t <= period/2 ? linear(t,0,period/2,0,100) : linear(t,period/2,period,100,0)
}else{
0
}


Set the delay to whatever you want. Or, it would be pretty easy to make the delay a random value, like this:

period = 6;
minDelay = 0;
maxDelay = 5;

seedRandom(index,true);
delay = random(minDelay,maxDelay);
if (time > delay){
t = (time-delay)%period;
t <= period/2 ? linear(t,0,period/2,0,100) : linear(t,period/2,period,100,0)
}else{
0
}



Dan



Respond to this post   •   Return to posts index


Re: Make a linear Loop
by Koby Goldberg on May 27, 2009 at 2:21:25 pm

You could also use the inPoint of the layer to choose the desired delay, in a way that if you move the layer in timeline to start later, the effect would start later.

In order to do this, you could use Dan's last expressions and just replace the delay to this:

delay = inPoint;

Koby.

Respond to this post   •   Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINETRAININGVIDEOS - REELSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]