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

Repeating Expression (not trying to make a looping expression)

Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

This is a little hard to explain, so if I'm confusing in any way, please let me know so I can clarify.

I have this code expression:

L = thisLayer;
s = thisComp.layer("Controller").effect("Speed")(1)*thisComp.frameDuration;
t2 = key(1).time;
t1 = t2-s;
t4 = key(2).time;
t3 = t4-s;
v1 = thisComp.layer("Controller").effect("Color 1")(1);
v2 = thisComp.layer("Controller").effect("Color 2")(1);
fadeIn = linear(time,t1,t2,v1,v2);
fadeOut = linear(time,t3,t4,v2,v1);

if (time<t1) {v1}
else if (time<t2) {fadeIn;}
else if (time<t3) {v2}
else if (time<t4) {fadeOut;}else{v1}

Currently, this code only works with 2 keyframes. It starts at v1; then Keframe 1 starts a linear transition (length dictated by "s" value) from v1 to v2; then Keyframe 2 starts a linear transition from v2 back to v1.

Here's what I would like to do: I would like to make it such that the code makes it automatically transition from v1 to v2 to v1 to v2 etc. no matter how many keyframes I have (not just with 2 keyframes). Is there a way to do this, or is this simply too crazy to be done?

I appreciate your time. Thanks for any help you can give! 🙂

TOPICS
Expressions , Scripting

Views

186

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jul 11, 2022 Jul 11, 2022

I think it will be something close to this:

s = thisComp.layer("Controller").effect("Speed")(1)*thisComp.frameDuration;
v1 = thisComp.layer("Controller").effect("Color 1")(1);
v2 = thisComp.layer("Controller").effect("Color 2")(1);

n = nearestKey(time).index;
if (time >= key(n).time) n++;
n = Math.min(n,numKeys);
t = key(n).time;
if (n%2){
  linear(time,t-s,t,v1,v2);
}else{
  linear(time,t-s,t,v2,v1);
}

Votes

Translate

Translate
Valorous Hero ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

Look into using Markers to trigger animations/behaviors. They will be a more efficient strategy to achieve what you want. 

Motion Graphics Brand Guidelines & Motion Graphics Responsive Design Toolkits

Votes

Translate

Translate

Report

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
Explorer ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

I did consider using markers instead of keyframes; however, I will be using this same code for multiple effects on the same layer, and I want the different effects to transition at different times. If I tie my code to specific markers, wouldn't I have to then have different code for all my different effects? And is there any particular benefit to use markers rather than keyframes to trigger animations/behaviors?

Also, on another note, I am unable to use the "Responsive Design" features of AfterEffects because I use CS5.5, before that was implemented.

Votes

Translate

Translate

Report

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 ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

I think it will be something close to this:

s = thisComp.layer("Controller").effect("Speed")(1)*thisComp.frameDuration;
v1 = thisComp.layer("Controller").effect("Color 1")(1);
v2 = thisComp.layer("Controller").effect("Color 2")(1);

n = nearestKey(time).index;
if (time >= key(n).time) n++;
n = Math.min(n,numKeys);
t = key(n).time;
if (n%2){
  linear(time,t-s,t,v1,v2);
}else{
  linear(time,t-s,t,v2,v1);
}

Votes

Translate

Translate

Report

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
Explorer ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

LATEST

This is exactly what I needed! Thank you so much! You're the best.

Votes

Translate

Translate

Report

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