Skip to content

Instantly share code, notes, and snippets.

@nariakiiwatani
Last active January 15, 2021 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nariakiiwatani/336daf51dafa8cfa53cd73649d79589e to your computer and use it in GitHub Desktop.
Save nariakiiwatani/336daf51dafa8cfa53cd73649d79589e to your computer and use it in GitHub Desktop.
AfterEffects Expression Utils
// demo: https://twitter.com/nariakiiwatani/status/1280689913202016256
const fadeIn = 0.2, fadeOut = 0.4,
lerp = (x, x0, x1, y0, y1) => (y0 + (y1 - y0) * (x - x0) / (x1 - x0)),
off = 0,
on = 1,
calcAlpha = (time, from, to, fadeIn, fadeOut) => (clamp(Math.min(lerp(time, from, from+fadeIn, off, on), lerp(time, to-fadeOut, to, on, off)),off,on));
([...Array(marker.numKeys).keys()]
.map(i=>marker.key(i+1))
.reduce((acc, m) => acc+calcAlpha(time, m.time, m.time+m.duration, fadeIn, fadeOut), 0))
*100
// demo: https://twitter.com/nariakiiwatani/status/1280358237246636032
[...Array(marker.numKeys).keys()]
.map(i=>marker.key(i+1))
.filter(m=>timeToFrames(m.time) <= timeToFrames(time) && timeToFrames(time) < timeToFrames(m.time+m.duration))
.map(m=>m.comment).join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment