Page 1 of 1

Increasing opacity

Posted: November 9th, 2007, 1:46 am
by ilmeri
Hi, and greetings to all forum members!

Im new to scripting, but understand some of the restrictions there are.
I'm wondering, if there's a way to do this:

I have 300 layers that i want to fade in randomly during few seconds.
Can i somehow achieve this with expressions?

What i was thinking was that i have a random number generator on each layer, and when it receives a value in certain range, it would execute the code that would fade the layer in. But what i know, it can't be done just like this.

Any tips?

And, is there a way to add an expression to multiple layers easily?

Thanks,

ilmeri

Posted: November 9th, 2007, 6:57 am
by Atomic
I'm not sure if your layers are text or images, but here is a link to a script that will import everything in a folder and make a comp for you.

http://www.aenhancers.com/viewtopic.php?t=719

viewtopic.php?t=102

The code in this script actually generates expressions for you, so it is possible to have expressions created automatically.

http://www.aenhancers.com/viewtopic.php?t=751

Here is a link to a script that takes a text file and makes 3D text that fades in and then out as it approaches and passes the camera.

http://www.aenhancers.com/viewtopic.php?t=142

Here is some code I use to make an expression only execute within a specific frame range.

Code: Select all

thisFrame=timeToFrames(t=time+thisComp.displayStartTime,fps=1.0/thisComp.frameDuration,isDuration=false); 
if (thisFrame>50 & thisFrame<104)
{
f=effect(1)(1);
div = Math.abs(Math.sin(2 * textIndex/textTotal -(time/2.5)*f)*100);
result = 0;
if (div) {result =300/div - 3;}
}
else{result =0;}

Posted: November 9th, 2007, 12:12 pm
by ilmeri
thanks..but i didn't really get it. :)

My comp is a logo cut to 300 layers. I want all the pieces to fade in during, let's say 2-3 seconds time, but each separately. It's painstaking to animate the opacity on all layers separately, by hand, so i was thinking if there's a way to fade the layers in with an expression.

Any more specific instructions?

Thanks anyway,

-ilmeri

Posted: November 10th, 2007, 2:24 am
by Paul Tuersley
This expression will fade up each layer over 1 second, starting somewhere between 0-2 seconds. Just add it to one layer's Opacity, copy that property, then select all the other layers and paste.

seedRandom(index, true);
theStart = random(0,2);
linear(time, theStart, theStart+1, 0, 100);


Here's a bit of an explanation about what it's doing:

// seedRandom gives some control over how random values are generated. setting "timeless = true" means the randomly generated value will not change on each frame.
seedRandom(index, true);

// generate a random value between 0 and 2 for the fade up start time
theStart = random(0,2);

// linear used to fade up from 0 to 100%, from theStart time to 1 sec later.
linear(time, theStart, theStart+1, 0, 100);

Posted: November 10th, 2007, 3:30 am
by ilmeri
sir, that's just awesome! and the copy / paste expression solved a lot too.

big thanks!

-ilmeri

Re: Increasing opacity

Posted: January 30th, 2008, 6:59 am
by to299
how should i change the script, when i don´t want it to fade in?
linear = ?

thanks alot.

Re: Increasing opacity

Posted: January 30th, 2008, 12:25 pm
by lloydalvarez
to299 wrote:how should i change the script, when i don´t want it to fade in?
This will cut the layers on. It actually does a 1 frame fade, you can change the fadeDurationInFrames variable to change the number of frame you'd like the fade to take.

-Lloyd

Code: Select all

fadeDurationInFrames = 1;

seedRandom(index, true);
theStart = random(0,2);
numFrames = fadeDurationInFrames*thisComp.frameDuration;
linear(time, theStart, theStart+numFrames, 0, 100); 

Re: Increasing opacity

Posted: January 31st, 2008, 11:33 am
by Disciple
How would you modify this expression if you have 10 layers in a comp that need the random opacity fade in, but there are 50 layers in the whole comp. In other words, the index count is not the right method (if I understand the expression correctly...)

Thanks
Alex

Re: Increasing opacity

Posted: January 31st, 2008, 12:16 pm
by lloydalvarez
Index is used to generate a unique random seed for each layer so that there are no repeats. So the expression should work regardless of how many layers you have in your comp

Re: Increasing opacity

Posted: January 31st, 2008, 12:29 pm
by Disciple
Stange, if I apply it to the opacity stream of a layer in a large comp the opacity goes straight to and stays at 100%

Re: Increasing opacity

Posted: January 31st, 2008, 12:58 pm
by lloydalvarez
try changing index with number:

Code: Select all

fadeDurationInFrames = 1;

seedRandom(1, true);
theStart = random(0,2);
numFrames = fadeDurationInFrames*thisComp.frameDuration;
linear(time, theStart, theStart+numFrames, 0, 100);


does that fix it? the thing is the same random seed will always generate the same number which is why you use index to give each layer a unique index seed, but to help you debug it you can use any number

Re: Increasing opacity

Posted: January 31st, 2008, 4:46 pm
by Paul Tuersley
lloydalvarez wrote:the thing is the same random seed will always generate the same number which is why you use index to give each layer a unique index seed
Actually, it won't. Multiple expressions with the same randomSeed will still generate different random values.

Disciple wrote:if I apply it to the opacity stream of a layer in a large comp the opacity goes straight to and stays at 100%
You're saying all layers with this expression have 100% Opacity from frame 1? Not sure what that could be. Add the Numbers effect to your layer, then add expressions like these to the Value property

time;

random(0,2);

seedRandom(1, true);
random(0,2);

seedRandom(1, true);
theStart = random(0,2);
linear(time, theStart, theStart+10, 0, 100);


and see what happens.

Paul

Re: Increasing opacity

Posted: January 31st, 2008, 10:17 pm
by Disciple
Well. the value that is displayed is 100...

Could this be due to the fact I'm running this project in 6.5?

Alex

Re: Increasing opacity

Posted: February 1st, 2008, 1:25 am
by Paul Tuersley
I don't know. It works in my copy of 6.5. Those were four separate expressions I was suggesting you try.

Paul

Re: Increasing opacity

Posted: February 2nd, 2008, 8:54 pm
by Disciple
Paul

I'm sorry, I tried this in the peak of crunch time while I was rendering the project. I guess I was hasty.
I'll try to give it a shot again asap.

Thanks
Alex