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

Expression Help: Running Expression after Keyframes

Community Beginner ,
Nov 05, 2022 Nov 05, 2022

Hey,

Whats the best way to adapt Dans oscillation script to run it after 2 keyframes that change opacity from 0-100 (basically making layer appear then oscillate opacity). Just been using a separate Transform currently but wondered if there was a way to run an expression only after the last keyframe?

//Dan's Oscillation Script

minVal = 20;
maxVal = 100;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2
avgVal + amp*(Math.sin(time*freq*Math.PI*2))
TOPICS
Expressions , Scripting
234
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
Enthusiast ,
Nov 05, 2022 Nov 05, 2022
minVal = 20;
maxVal = 100;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2;
result = avgVal + amp*(Math.sin(time*freq*Math.PI*2));

//linear(time, key(2).time, key(2).time+1, value, result);
result = result * (value/100);

 

Here are a couple of options. Comment out the other last line to try each. 

 

The linear one uses time to control a fade from the keyframed values to the oscillating result, from the time of the second keyframe to 1 second after. So this will do a clean fade up then transition to the oscillation.

The other just multiples the oscillation result by 0 > 1 as you increase the opacity to 100, so it oscillates through the fade up too.

You could just use an if (time > key(2).time) result else value; but that would abruptly switch to whatever the oscillating value is on the frame after the keyframe

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 ,
Nov 05, 2022 Nov 05, 2022
LATEST

You could try this:

if (numKeys > 1 && time >= key(numKeys).time){
  t = time - key(numKeys).time;
  minVal = 20;
  maxVal = key(numKeys).value;
  freq = 1; // oscillations per second
  avgVal = (minVal + maxVal)/2;
  amp = (maxVal - minVal)/2;
  avgVal + amp*(Math.cos(t*freq*Math.PI*2));
}else{
  value;
}
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