Skip to content

Instantly share code, notes, and snippets.

@JohnGemstone
Created November 7, 2025 03:07
Show Gist options
  • Save JohnGemstone/453d69ecfffeedfaf7f2363befb3b2af to your computer and use it in GitHub Desktop.
Save JohnGemstone/453d69ecfffeedfaf7f2363befb3b2af to your computer and use it in GitHub Desktop.
AfterEffects trolly loop for accumulating values over each iteration
loopDur = key(numKeys).time - key(1).time;
// only run while this layer is active
if (time < inPoint) {
// before layer starts → hold first keyframe
key(1).value;
} else if (time > outPoint) {
// after layer ends → hold the final accumulated value at outPoint
tEnd = outPoint - key(1).time;
loopCountEnd = Math.floor(tEnd / loopDur);
tInLoopEnd = (tEnd % loopDur) + key(1).time;
loopValueEnd = valueAtTime(tInLoopEnd);
offsetEnd = (key(numKeys).value - key(1).value) * loopCountEnd;
loopValueEnd + offsetEnd;
} else {
// active portion → normal accumulation
t = time - key(1).time;
loopCount = Math.floor(t / loopDur);
tInLoop = (t % loopDur) + key(1).time;
loopValue = valueAtTime(tInLoop);
offset = (key(numKeys).value - key(1).value) * loopCount;
loopValue + offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment