Skip to content

Instantly share code, notes, and snippets.

@GoodBoyNinja
Created June 7, 2021 21:02
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/fcd5e070fc0005cf57f4d99eb606569b to your computer and use it in GitHub Desktop.
Save GoodBoyNinja/fcd5e070fc0005cf57f4d99eb606569b to your computer and use it in GitHub Desktop.
A basic lerp function for ExtendScript. amt is similar to t in the more conventional naming of lerp. This function is similar to the Linear function inside After-Effects expression, however it does not let you map the range to something else, and the argument list order is different. This function works with arrays of numbers as well (for exampl…
function lerp(start, end, amt) {
if (start == undefined || end == undefined || amt == undefined) {
// can't lerp, start end amount is missing
if (start !== undefined) {
return start;
}
return 0;
}
function oneDLerp(start, end, amt) {
try {
if (amt == undefined) {
if (start !== undefined) {
return start;
}
if (end !== undefined) {
return end;
}
return 0;
}
amt = amt < 0 ? 0 : amt > 1 ? 1 : amt;
return (1 - amt) * start + amt * end;
} catch (e) {
// error in oneDLerp, you can print or alert the error
}
}
if (start.length >= 1) {
var result = [];
for (lrp = 0; lrp < start.length; lrp++) {
result.push(oneDLerp(start[lrp], end[lrp], amt));
}
return result;
} else {
return oneDLerp(start, end, amt);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment