Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

opacity on off expression

Community Beginner ,
May 15, 2021 May 15, 2021

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  ?

TOPICS
Expressions , How to
12.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 15, 2021 May 15, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 15, 2021 May 15, 2021

This should work:

Math.floor(timeToFrames(time)/10)%2 ? 0 : 100
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2022 Feb 06, 2022

Is there a way to randomize this across a long timeline instead of constant pulsing?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2022 Feb 06, 2022

Probably. Depends on what you mean though. What are you randomizing? What are the constraints?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2022 Feb 06, 2022

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2022 Feb 06, 2022

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2022 Feb 06, 2022

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)

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 06, 2022 Feb 06, 2022

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)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2023 Oct 10, 2023
LATEST

Great code! Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines