Cubic Bezier v0.1.0 CubicBezier

Elixir port of the the JavaScript port of Webkit implementation of CSS cubic-bezier(p1x, p1y, p2x, p2y) by http://mck.me

http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h https://gist.github.com/mckamey/3783009

Link to this section Summary

Functions

Given x (a float between 0.0 and 1.0), compute the y.

Link to this section Functions

Link to this function

solve(x, easing_or_control_points, opts \\ [])

solve(float(), atom() | tuple(), list()) :: float()

Given x (a float between 0.0 and 1.0), compute the y.

Either an easing atom or control points tuple can be provided.
Most common easing equations are support, but if an unsupported atom is given, the control points for :linear are returned.

See: https://gist.github.com/terkel/4377409

Options

  • duration (integer) - can provide greater accuracy.
    The default duration is 400 (ms), which is a common animation / transition duration.

Examples

iex> CubicBezier.solve(0.50, :ease_out_quad)
0.7713235628639843
iex> CubicBezier.solve(0.5, {0.250,  0.460,  0.450,  0.940})
0.7713235628639843
iex(1)> Enum.map([0.0, 0.25, 0.5, 0.75, 1.0], fn x -> 
...(1)> {x, Float.round(CubicBezier.solve(x, :ease_out_quad), 3)}
...(1)> end)
[{0.0, 0.0}, {0.25, 0.453}, {0.5, 0.771}, {0.75, 0.936}, {1.0, 1.0}]