# FFmpeg custom expressions, made with xfade-easing.sh v. 3.6.2
# by Raymond Luckhurst, https://scriptit.uk, https://github.com/scriptituk/xfade-easing

# Xfade easing expressions, script for -/filter_complex filterchains

LINEAR
st(0, P)

QUADRATIC-IN
st(0, P * (2 - P))

QUADRATIC-OUT
st(0, P * P)

QUADRATIC-IN-OUT
st(0, if(lt(P, 0.5), 2 * P * P, 2 * P * (2 - P) - 1))

CUBIC-IN
st(0, 1 - (1-P)^3)

CUBIC-OUT
st(0, P^3)

CUBIC-IN-OUT
st(0, if(lt(P, 0.5), 4 * P^3, 1 - 4 * (1-P)^3))

QUARTIC-IN
st(0, 1 - (1-P)^4)

QUARTIC-OUT
st(0, P^4)

QUARTIC-IN-OUT
st(0, if(lt(P, 0.5), 8 * P^4, 1 - 8 * (1-P)^4))

QUINTIC-IN
st(0, 1 - (1-P)^5)

QUINTIC-OUT
st(0, P^5)

QUINTIC-IN-OUT
st(0, if(lt(P, 0.5), 16 * P^5, 1 - 16 * (1-P)^5))

SINUSOIDAL-IN
st(0, sin(P * PI / 2))

SINUSOIDAL-OUT
st(0, 1 - cos(P * PI / 2))

SINUSOIDAL-IN-OUT
st(0, (1 - cos(P * PI)) / 2)

EXPONENTIAL-IN
st(0, if(gte(P, 1), 1, 1 - 2^(-10 * P)))

EXPONENTIAL-OUT
st(0, if(lte(P, 0), 0, 2^(10 * P - 10)))

EXPONENTIAL-IN-OUT
st(0,
 if(lt(P, 0.5),
  if(lte(P, 0), 0, 2^(20 * P - 11)),
  if(gte(P, 1), 1, 1 - 2^(9 - 20 * P))
 )
)

CIRCULAR-IN
st(0, sqrt(P * (2 - P)))

CIRCULAR-OUT
st(0, 1 - sqrt(1 - P * P))

CIRCULAR-IN-OUT
st(0,
 if(lt(P, 0.5),
  1 - sqrt(1 - 4 * P * P),
  1 + sqrt(4 * P * (2 - P) - 3)
 ) / 2
)

ELASTIC-IN
st(0, 1 - cos(P * 20.944) / 2^(10 * P))

ELASTIC-OUT
st(0, cos((1-P) * 20.944) / 2^(10 * (1-P)))

ELASTIC-IN-OUT
st(0,
 st(1, cos(st(2, 2 * P - 1) * 13.9626) / 2);
 st(2, 2^(10 * ld(2)));
 if(lt(P, 0.5), ld(1) * ld(2), 1 - ld(1) / ld(2))
)

BACK-IN
st(0, 1 - (1-P)^2 * (1 - P * 2.70158))

BACK-OUT
st(0, P * P * (P * 2.70158 - 1.70158))

BACK-IN-OUT
st(0,
 if(lt(P, 0.5),
  2 * P * P * (2 * P * 3.59491 - 2.59491),
  1 - 2 * (1-P)^2 * (4.59491 - 2 * P * 3.59491)
 )
)

BOUNCE-IN
st(0,
  if(lt(P, 0.363636),
   7.5625 * P * P,
   if(lt(P, 0.727273),
    7.5625 * (P - 0.545455)^2 + 0.75,
    if(lt(P, 0.909091),
     7.5625 * (P - 0.818182)^2 + 0.9375,
     7.5625 * (P - 0.954545)^2 + 0.984375
    )
   )
  )
)

BOUNCE-OUT
st(0,
 st(0, 1 - P);
 1 - (
  if(lt(ld(0), 0.363636),
   7.5625 * ld(0) * ld(0),
   if(lt(ld(0), 0.727273),
    7.5625 * (ld(0) - 0.545455)^2 + 0.75,
    if(lt(ld(0), 0.909091),
     7.5625 * (ld(0) - 0.818182)^2 + 0.9375,
     7.5625 * (ld(0) - 0.954545)^2 + 0.984375
    )
   )
  )
 )
)

BOUNCE-IN-OUT
st(0,
 st(1,
  st(0, st(2, lt(P, 0.5) * 2 - 1) * (1 - 2 * P));
  if(lt(ld(0), 0.363636),
   7.5625 * ld(0) * ld(0),
   if(lt(ld(0), 0.727273),
    7.5625 * (ld(0) - 0.545455)^2 + 0.75,
    if(lt(ld(0), 0.909091),
     7.5625 * (ld(0) - 0.818182)^2 + 0.9375,
     7.5625 * (ld(0) - 0.954545)^2 + 0.984375
    )
   )
  )
 );
 (1 - ld(2) * ld(1)) / 2
)

SQUAREROOT-IN
st(0, 1 - sqrt((1-P)))

SQUAREROOT-OUT
st(0, sqrt(P))

SQUAREROOT-IN-OUT
st(0, if(lt(P, 0.5), sqrt(P / 2), 1 - sqrt((1-P) / 2)))

CUBEROOT-IN
st(0, pow(P, 0.333333))

CUBEROOT-OUT
st(0, 1 - pow((1-P), 0.333333))

CUBEROOT-IN-OUT
st(0, if(lt(P, 0.5), pow(P / 4, 0.333333), 1 - pow((1-P) / 4, 0.333333)))
