12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Ease.mli *)typet=float->floatletlinear(t:float):float=t(*****************************************************************************)(* The families *)(*****************************************************************************)letquad(t:float):float=t*.tletcubic(t:float):float=t*.t*.tletsine(t:float):float=1.-.cos(t*.Float.pi/.2.)(* Penner's constant: 10% of overshoot (see Ease.mli) *)lets=1.70158letback(t:float):float=((s+.1.)*.t*.t*.t)-.(s*.t*.t)(* a sine of period 0.3, its amplitude growing from 2^-10 to 1; ends at
* exactly 0 and 1 *)letelastic(t:float):float=ift<=0.then0.elseift>=1.then1.else-.(2.**((10.*.t)-.10.))*.sin(((10.*.t)-.10.75)*.(2.*.Float.pi/.3.))(* Penner writes the bounce the way it falls (its out curve): four
* parabolas, each touching 1, of heights 1/4, 1/16 and 1/64 below it
* -- a ball losing half its speed each time *)letbounce_out(t:float):float=letn=7.5625andd=2.75inift<1./.dthenn*.t*.telseift<2./.dthenlett=t-.(1.5/.d)in(n*.t*.t)+.0.75elseift<2.5/.dthenlett=t-.(2.25/.d)in(n*.t*.t)+.0.9375elselett=t-.(2.625/.d)in(n*.t*.t)+.0.984375letsmoothstep(t:float):float=t*.t*.(3.-.(2.*.t))(*****************************************************************************)(* Out and in-out, from any curve *)(*****************************************************************************)letout(f:t):t=funt->1.-.f(1.-.t)letin_out(f:t):t=funt->ift<0.5thenf(2.*.t)/.2.else1.-.(f(2.-.(2.*.t))/.2.)(* its in curve is its out one run backwards *)letbounce:t=outbounce_outletall:(string*t)list=[("linear",linear)]@List.concat_map(fun(name,f)->[("in_"^name,f);("out_"^name,outf);("in_out_"^name,in_outf)])[("quad",quad);("cubic",cubic);("sine",sine);("back",back);("elastic",elastic);("bounce",bounce)]@[("smoothstep",smoothstep)]