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

Looping on Opacity

Engaged ,
Jun 12, 2025 Jun 12, 2025

Hi there --

I've been trying to figure out how to loop the opacity of a layer with expressions for two days. If your first thought is, "he must not be very smart," I won the 7th grade spelling bee and the 9th grade Science award. It's been all downhill from there, though. I tried to get help from ChatGPT, but Chad (my bot) kept throwing in extra info that made what seemed like a simple question more complex than necessary. I would do what he said, then tell him it didn't loop. His usual response was along the lines of, "Great! You're on the right track. What an insightful question. Just do this, and it will loop just fine." I fell for it almost every time, and was crushed when it didn't loop the way Chad assured me it would. After a while it dawned on me that Chad doesn't have eyes and has no idea what the code he sends me looks like on screen.   I tell you all that so you know I am the kind of person who only asks for help when he really really needs it.


If I can get something small to loop, I can build from there. I learn best from written instructions. I really miss the days when software came with a written manual. 

Best regards,
Scott Williams

 

TOPICS
Expressions , How to , Scripting
266
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

correct answers 1 Correct answer

Explorer , Jun 12, 2025 Jun 12, 2025

Chad can be a bonehead, and needs to be asked the most concise questions in order to get things right.

I too,  barely know squat about expressions, but have learned a bit on how to use ChatGPT to actually produce some stuff I never imagined possible.   After awhile, it trains you to know what to ask for.   
One place to start is not using regulary ChatGPT, but go search for  "
https://chatgpt.com/gpts
where you can  "Discover and create custom versions of ChatGPT that combine instructions, extra kno

...
Translate
Community Expert ,
Jun 12, 2025 Jun 12, 2025

You need at least two keyframes. If one is at 0% and the other is at 100%, and they are 10 frames apart:

loopOut("pingpong");

The opacity will animate from 0 to 100 to 0 to 100 for the length of the comp.

 

If you use:

loopOut();

The expression defaults to loopOut("cycle"), so the opacity will go from 0 to 100, then snap to 0 on the next frame, and animate to 100 again and again.

 

The other options are "continue" and "offset," but neither will create a loop because Opacity has a numerical limit of zero to one hundred. Those options work for properties like rotation and position, which do not have limits to their values.

 

I hope this helps. If you just start typing loopOut, the parentheses will auto-generate. Then, adding Quotation marks will give you a drop-down/auto-complete popup that will complete the loopOut expression without errors. 

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 ,
Jun 12, 2025 Jun 12, 2025

Or, if you don't want to use keyframes, you could just use one of the trig functions, like this:

freq = 1; // loop once per second
50*(Math.cos(time*freq*Math.PI*2 + Math.PI)+1);

 

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
Explorer ,
Jun 12, 2025 Jun 12, 2025

Chad can be a bonehead, and needs to be asked the most concise questions in order to get things right.

I too,  barely know squat about expressions, but have learned a bit on how to use ChatGPT to actually produce some stuff I never imagined possible.   After awhile, it trains you to know what to ask for.   
One place to start is not using regulary ChatGPT, but go search for  "
https://chatgpt.com/gpts
where you can  "Discover and create custom versions of ChatGPT that combine instructions, extra knowledge, and any combination of skills" and search for After Effects related GPT's.   One populat one is "AE Expressions Master"

Then you'd want to ask something like:  "Can I have an expression that i can apply to my Opacity that will loop back and forth between two variables based on a frame duration determined by another variable?"

that's the only question I asked, and here's the very first result that I got,  which works right off the batt and can be easily cusomized as needed:

// Define your min and max opacity values
var minVal = 20;
var maxVal = 100;

// Set the duration in frames for a complete ping-pong cycle (forward + backward)
var frameDuration = 30;

// Convert frame duration to time (seconds)
var cycleDuration = thisComp.frameDuration * frameDuration;

// Normalize time within the full cycle
var cycleTime = time % (cycleDuration);

// Calculate normalized progress through half of the cycle
var progress = cycleTime / (cycleDuration / 2);

// Ping-pong interpolation
if (progress < 1) {
linear(progress, 0, 1, minVal, maxVal); // going up
} else {
linear(progress, 1, 2, maxVal, minVal); // going down
}

 

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 ,
Jun 12, 2025 Jun 12, 2025

Chat GPT gave you a very complicated solution. I would have used Dan's simple trig function. A simple min/max addition would let you oscillate between 20% and 80% if you wanted. 

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
Engaged ,
Jun 13, 2025 Jun 13, 2025
LATEST

Teach a man to fish, and he eats for a lifetime. While I couldn't follow your logic, I followed your advice and got help from AE Expressions Master. I have four layers that I want to cycle through at five second intervals. So for each layer I used a variant of this code:
period = 20;
t = time % period;
(t < 5) ? 0 : (t < 10) ? 100 : 0;

 

Thanks so much!

 

 

 

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