Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoodBoyNinja/e2225da88fee6b553657bdd9b73f8ff0 to your computer and use it in GitHub Desktop.
Save GoodBoyNinja/e2225da88fee6b553657bdd9b73f8ff0 to your computer and use it in GitHub Desktop.
When applied to a position property, it places it on the edges of the comp. Use "time" as the percentage input like in the example below to drive the animation.
function MoveAlongEdgesOfComp(percent, marginpercent) {
percent = (percent === undefined) ? 0 : percent % 100;
marginpercent = (marginpercent === undefined) ? 0 : clamp(marginpercent, 0, 100);
// convert the original percent value to both horizontal and vertical percent values to drive the motion
horizontalpercent = (percent >= 25 && percent <= 50) ? 100 : (percent >= 75 && percent <= 100) ? 0 : (percent < 25) ? (percent * 4) : (100 - (4 * (percent % 25)));
verticalpercent = (percent >= 0 && percent <= 25) ? 0 : (percent >= 50 && percent <= 75) ? 100 : (percent < 50) ? (percent - 25) * 4 : (100 - (4 * (percent % 25)));
midPoint = [thisComp.width * 0.5, thisComp.height * 0.5]; // use the linear function to drive each dimension
xLoc = linear(horizontalpercent, 0, 100, 0, thisComp.width);
yLoc = linear(verticalpercent, 0, 100, 0, thisComp.height);
finalPoint = [linear(marginpercent, 0, 100, xLoc, midPoint[0]), linear(marginpercent, 0, 100, yLoc, midPoint[1]), 0];
return finalPoint;
}
MoveAlongEdgesOfComp(time * 20, 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment