Skip to main content
Participant
February 18, 2024
Answered

expression linear functionc

  • February 18, 2024
  • 1 reply
  • 787 views

Hello, I'd like to increase my opacity to 80% and then decrease it from 80% to 0% in the following linear function.

driver=thisComp.layer("Sun").transform.position[0]
SunMin=-180;
SunMax=2076;
SkyMin=0;
SkyMax=80;
 
if (driver<=2076){
driver=Math.abs(driver)
 
}
 
x=linear(driver,SunMin,SunMax,SkyMin,SkyMax);
 
 

 

 

I think I need to use a condition. I've tried with the x position so that at a certain distance the opacity reverses, but without success :/. Can anyone help me?

This topic has been closed for replies.
Correct answer Dan Ebberts

Ah, that's a little more complex. Maybe like this then:

driver = thisComp.layer("Sun").transform.position[0];
SunMin=-180;
SunMax=2076;
SkyMin=0;
SkyMax=80;

val = SkyMin;
x = (driver-SunMin)%(SunMax-SunMin);
if (x >= 0){
  n = Math.floor((driver-SunMin)/(SunMax-SunMin));
  if (n%2) {
    val = linear(x,0,SunMax-SunMin,SkyMax,SkyMin);  
  }else{
    val = linear(x,0,SunMax-SunMin,SkyMin,SkyMax);
  }
}
val

1 reply

Dan Ebberts
Community Expert
Community Expert
February 18, 2024

There are a number of ways to do it, but this one is pretty close to what you have:

driver = thisComp.layer("Sun").transform.position[0]
SunMin=-180;
SunMax=2076;
SkyMin=0;
SkyMax=80;
if (driver > SunMax) driver = 2*SunMax - driver;
linear(driver,SunMin,SunMax,SkyMin,SkyMax);
Participant
February 18, 2024

Hi Dan thanks for your time, but it doesnt work like i would like, when the opacity is equal to 80% it juste go back to 0, i would like to make it slowly decrsease to 0 like a loopOut 'ping-pong' and then go back to 80% again

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
February 18, 2024

Ah, that's a little more complex. Maybe like this then:

driver = thisComp.layer("Sun").transform.position[0];
SunMin=-180;
SunMax=2076;
SkyMin=0;
SkyMax=80;

val = SkyMin;
x = (driver-SunMin)%(SunMax-SunMin);
if (x >= 0){
  n = Math.floor((driver-SunMin)/(SunMax-SunMin));
  if (n%2) {
    val = linear(x,0,SunMax-SunMin,SkyMax,SkyMin);  
  }else{
    val = linear(x,0,SunMax-SunMin,SkyMin,SkyMax);
  }
}
val