Skip to content

Instantly share code, notes, and snippets.

@yone80
Last active October 25, 2017 11:51
Show Gist options
  • Save yone80/90e1afe3970fbcdd06a34dbde85d230a to your computer and use it in GitHub Desktop.
Save yone80/90e1afe3970fbcdd06a34dbde85d230a to your computer and use it in GitHub Desktop.
Shape on path - Aftereffects Expression
dist = effect("Offset")("Slider"); // Position on path.
w = effect("Width")("Slider"); // Normal direction width.
restpath = thisProperty;
targetpath = thisComp.layer("Path").content("Shape 1").content("Path 1").path; // Target Path
refpt = restpath.points();
refintan = restpath.inTangents();
refouttan = restpath.outTangents();
points =[];
intangents = [];
outtangents = [];
for(i=0; i<refpt.length; i++){
rest = refpt[i];
f = dist + rest[0] / thisComp.width;
pathpoint = targetpath.pointOnPath(f);
pathnormal = targetpath.normalOnPath(f);
angle = Math.atan2(-pathnormal[0], pathnormal[1]);
intanx = refintan[i][0] * Math.cos(angle) - refintan[i][1] * Math.sin(angle);
intany = refintan[i][0] * Math.sin(angle) + refintan[i][1] * Math.cos(angle);
outtanx = refouttan[i][0] * Math.cos(angle) - refouttan[i][1] * Math.sin(angle);
outtany = refouttan[i][0] * Math.sin(angle) + refouttan[i][1] * Math.cos(angle);
points.push( pathpoint + pathnormal * rest[1] *w);
intangents.push( [intanx, intany * w] );
outtangents.push( [ outtanx, outtany * w] );
}
createPath(points, intangents, outtangents);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment