Skip to content

Instantly share code, notes, and snippets.

@yone80
Last active November 8, 2017 00:19
Show Gist options
  • Save yone80/389722e4d70981828b41ce3b3d4cefce to your computer and use it in GitHub Desktop.
Save yone80/389722e4d70981828b41ce3b3d4cefce to your computer and use it in GitHub Desktop.
Shape on motion path - Aftereffects Expression
seg = Math.floor( Math.max(effect("Segments")("Slider"), 2) );
starttime = effect("Start Time")("Slider");
endtime = effect("End Time")("Slider");
smooth = effect("Smooth")("Checkbox") > 0;
targetlayer = thisComp.layer("Tip");
timemin = Math.min(starttime, endtime);
timemax = Math.max(starttime, endtime);
cv = [];
for(var i = 0; i < seg + 1; i++){
f = linear(i, 0, seg, timemin, timemax);
cv.push( fromCompToSurface( targetlayer.toComp( targetlayer.anchorPoint, f ) ) );
}
// quadratic curve bezier approximation.
if(smooth){
points = [];
intan = [];
outtan = [];
for(var i = 0; i < cv.length; i++){
if(i == 0){
points.push(cv[i]);
intan.push([0,0]);
outtan.push( (cv[i+1] - cv[i]) * (2 / 3) );
}else if(i == cv.length-1){
points.push(cv[i]);
intan.push( (cv[i-1] - cv[i]) * (2 / 3) );
outtan.push([0,0]);
}else{
pos = cv[i] + div(cv[i+1] - cv[i], 2);
points.push(pos);
intan.push( (cv[i] - pos) * (2 / 3) );
outtan.push( (cv[i+1] - pos) * (2 / 3) );
}
}
createPath(points, intan, outtan, false);
}
if(!smooth) createPath(cv, [], [], false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment