Loop Path Animations

​​Paste the following expression in the position shown

try {
    timeStart = thisProperty.key(1).time; ///< gets the time of the specified keyframe
    duration = thisProperty.key(thisProperty.numKeys).time - timeStart;
    pingPong = false; ///< If you want the animation to loop back and forth, change to true
    
    /// @note quantifies the elapsed time by duration
    quant = Math.floor((time - timeStart) / duration);
    /// @note has not started yet
    if (quant < 0) quant = 0;
    / / / @ note return
    if (quant % 2= =1 && pingPong == true) {
        t = 2 * timeStart + (quant + 1) * duration - time;
    } else{ t = time - quant * duration; }}catch(err) {
    t = time;
}
thisProperty.valueAtTime(t)
Copy the code

Note: Copy to another layer by right clicking “Copy Expression Only”

)

Random Change to Specific Colors

colors = [[0.194.209.255] /255[115.92.221.255] /255[179.60.142.255] /255[242.27.63.255] /255]; 
easeTime = 2.; 
segDur = 2; 
curSeg = Math.floor(time/segDur); 
t = time %s egDur; 
seedRandom(curSeg, true);                 ///< random number seed to ensure that the generated random sequence is different
idx1 = Math.floor(random(colors.length)); ///< random color index
seedRandom(curSeg-1.true); 
idx0 = Math.floor(random(colors.length)); 
ease(t, 0, easeTime, colors[idx0], colors[idx1])
Copy the code

Note: Using color controls instead of manually entering color codes, this is shown below.

colors = [effect("Color Control") ("Color") /255, effect("Color Control 2") ("Color") /255, effect("Color Control 3") ("Color") /255, effect("Color Control 4") ("Color") /255];
Copy the code

Ultimate Number Counter

The following expression automatically adds $% to a number and specifies the number of decimal places to keep

slider = effect("Slider Control") ("Slider"); ///< use the Angle control
numDecimals = 2;
commas = false;
dollarSign = true;
percentSign = false;
s = slider.value.toFixed(numDecimals); ///< retain the specified number of bits, converted to a string
prefix = "";
suffix = "";
if (s[0] = ="-"){
  prefix = "-";
  s = s.substr(1);
}
if(dollarSign) prefix += "$";
if(percentSign) suffix = "%";
if (commas){ ///< if there is a comma
  decimals = "";
  if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0, s.length - (numDecimals + 1));
  }
  /// @note 
  /// -s.length indicates the 0th element at the beginning, and extracts (s.length-1)%3 + 1 characters from that position to the end
  outStr = s.substr(-s.length, (s.length-1) %3 + 1);
  for (i = Math.floor((s.length-1) /3); i > 0; i--){
    outStr += "," + s.substr(-i*3.3);
  }
  prefix + outStr + decimals + suffix;
}else{
  prefix + s + suffix;
}
Copy the code

4. Fade Layer Based on Start and End Points

The expression is as follows:

fade = 1; ///< control fade duration (s)
fadeIn = (time - inPoint) / fade;
fadeOut = (outPoint - time) / fade;
if (time < inPoint + fade) {
    ease(fadeIn, 0.1) * value; / / / < fade in
} else if (time > outPoint - fade) {
    ease(fadeOut, 0.1) * value; / / / < fade out
} else {
    value;
}
Copy the code

Trigger Opacity with Checkbox Control

The expression is as follows:

if(effect("Checkbox Control") ("Checkbox") = =0) 
    {0};
else 
    {100};
Copy the code

Note: you can swap the values inside {} to get more custom results.