Copy link to clipboard
Copied
sorry, i am a beginner ...
i wanted to know if i can make the opacity of a layer going on and off (say 10 frames on and 10 frames off) with an expression ?
Copy link to clipboard
Copied
Sure. Could be as simple as
Math.floor(time%10)*100;
which creates an alternating on/off animation every ten frames when applied to the opacity.
Mylenium
Copy link to clipboard
Copied
This should work:
Math.floor(timeToFrames(time)/10)%2 ? 0 : 100
Copy link to clipboard
Copied
Is there a way to randomize this across a long timeline instead of constant pulsing?
Copy link to clipboard
Copied
Probably. Depends on what you mean though. What are you randomizing? What are the constraints?
Copy link to clipboard
Copied
I have a collection of the same logo repeated across the screen and the client wants the opacity to slowly pulse but wants it to occur randomly. I can get the pulse to work properly but I don't have a way to randomize the timing of when they fade and reappear.
Copy link to clipboard
Copied
That's still pretty vague. This might be one way:
// min/max on & off times in frames
minOn = 5;
maxOn = 40;
minOff = 5;
maxOff = 40;
t = tPrev = 0;
seg = 1;
while (t <= time){
seedRandom(seg,true);
myOn = framesToTime(random(minOn,maxOn));
myOff = framesToTime(random(minOff,maxOff));
tPrev = t;
t += myOn + myOff;
}
time - tPrev < myOn ? 100 : 0
Copy link to clipboard
Copied
Thank you, Dan. This is almost exactly what I was looking for. Is there a way to smooth the transition by the amount of frames? Similar to the fade duration included in this expression.
fadeDuration = thisComp.frameDuration*48;
maxDelay = .5;
seedRandom(index,true);
delay = random(maxDelay);
t = time -(inPoint + delay);
linear(t,0,fadeDuration,0,100)
Copy link to clipboard
Copied
Something like this maybe:
// min/max on & off times in frames
minOn = 10;
maxOn = 40;
minOff = 10;
maxOff = 40;
fadeFrames = 5; // should be less than minOn and minOff
t = tPrev = 0;
seg = 1;
while (t <= time){
seedRandom(seg,true);
myOn = framesToTime(random(minOn,maxOn));
myOff = framesToTime(random(minOff,maxOff));
tPrev = t;
t += myOn + myOff;
}
t2 = time - tPrev;
f = framesToTime(fadeFrames);
t2 < myOn ? linear(t2,0,f,0,100) : linear(t2,myOn,myOn+f,100,0)
Copy link to clipboard
Copied
Great code! Thanks!