一、循环路径动画(Loop Path Animations)
在如图所示的位置,黏贴以下表达式
try {
timeStart = thisProperty.key(1).time; ///< 获取指定关键帧的时间
duration = thisProperty.key(thisProperty.numKeys).time - timeStart;
pingPong = false; ///< 如果你想要来回循环动画,请更改为 true
/// @note 用 duration 量化经过的时间
quant = Math.floor((time - timeStart) / duration);
/// @note 尚未开始
if (quant < 0) quant = 0;
/// @note 回程
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 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); ///< 随机数种子,确保生成的随机序列不同
idx1 = Math.floor(random(colors.length)); ///< 随机颜色索引
seedRandom(curSeg-1, true);
idx0 = Math.floor(random(colors.length));
ease(t, 0, easeTime, colors[idx0], colors[idx1])
注意: 使用颜色控制而不是手动输入颜色代码,则如下所示。
colors = [effect("Color Control")("Color")/255, effect("Color Control 2")("Color")/255, effect("Color Control 3")("Color")/255, effect("Color Control 4")("Color")/255];
三、终极数字计数器(Ultimate Number Counter)
以下表达式可以实现给数字自动添加 $ % , 的功能 而且可以指定保留的小数点后位数
slider = effect("Slider Control")("Slider"); ///< 使用角度控件
numDecimals = 2;
commas = false;
dollarSign = true;
percentSign = false;
s = slider.value.toFixed(numDecimals); ///< 保留指定的位数,转成字符串
prefix = "";
suffix = "";
if (s[0] == "-"){
prefix = "-";
s = s.substr(1);
}
if(dollarSign) prefix += "$";
if(percentSign) suffix = "%";
if (commas){ ///< 如果有逗号
decimals = "";
if (numDecimals > 0){
decimals = s.substr(-(numDecimals + 1));
s = s.substr(0, s.length - (numDecimals + 1));
}
/// @note
/// -s.length 表示开头第 0 个元素,从该位置到结尾提取 (s.length-1)%3 + 1 个字符
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;
}
四、基于开始和结束点的淡入淡出层(Fade Layer Based on Start and End Points)
表达式如下:
fade = 1; ///< 控制渐隐持续时间(秒)
fadeIn = (time - inPoint) / fade;
fadeOut = (outPoint - time) / fade;
if (time < inPoint + fade) {
ease(fadeIn, 0, 1) * value; ///< 淡入
} else if (time > outPoint - fade) {
ease(fadeOut, 0, 1) * value; ///< 淡出
} else {
value;
}
五、用复选框控件触发不透明度(Trigger Opacity with Checkbox Control)
表达式如下:
if(effect("Checkbox Control")("Checkbox") == 0)
{0};
else
{100};
注意: 你可以交换 {} 里面的值来得到更多的自定义结果。