Last active
November 8, 2017 00:19
-
-
Save yone80/389722e4d70981828b41ce3b3d4cefce to your computer and use it in GitHub Desktop.
Shape on motion path - Aftereffects Expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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