Curves.Bezier.Predefined (curves v1.0.1)

Copy Markdown View Source

Shortcuts for quickly getting a list of points that can be passed into Curves.define_bezier/1

Usage

    iex> alias Curves.Bezier.Predefined
    iex> Predefined.get_coords(:linear_up_right)
    [{0.0, 0.0}, {1.0, 1.0}]
    iex> [:ease | _] = Predefined.list()
    iex> Predefined.get_coords(:ease_in_out_cubic)
    [{0.0, 0.0}, {0.65, 0.0}, {0.35, 1.0}, {1.0, 1.0}]

The names are the usual easing names (as on easings.net, and in CSS), but the points are this library's own, and some differ from those curves: :ease, :ease_in and :ease_in_cubic are the same curve, as are :ease_out and :ease_out_cubic, and :ease_in_out and :ease_in_out_cubic. For an exact CSS timing function, give its points yourself: CSS's ease is Curves.define_bezier([{0, 0}, {0.25, 0.1}, {0.25, 1}, {1, 1}]), and ease-in-out is [{0, 0}, {0.42, 0}, {0.58, 1}, {1, 1}].

Each picture shows the curve in blue and the points that shape it in orange.

Cubic

:ease:ease_in:ease_in_back
:ease_in_circ:ease_in_cubic:ease_in_expo
:ease_in_out:ease_in_out_back:ease_in_out_circ
:ease_in_out_cubic:ease_in_out_expo:ease_in_out_quad
:ease_in_out_quart:ease_in_out_quint:ease_in_out_sine
:ease_in_quad:ease_in_quart:ease_in_quint
:ease_in_sine:ease_out:ease_out_back
:ease_out_circ:ease_out_cubic:ease_out_expo
:ease_out_quad:ease_out_quart:ease_out_quint
:ease_out_sine

Quadratic

:quadratic_down:quadratic_left:quadratic_right
:quadratic_up

Linear

:linear:linear_down_right:linear_horizontal
:linear_up_right:linear_vertical

Summary

Types

A list of curve keys

A map of useful info about a predefined curve.

A list of curve type info

Functions

Return a map with details about a specific curve.

Return the list of {x, y} points for a predefined curve. A name that isn't one raises an ArgumentError.

Return a list of all keys that can be used with get_coords/1

Return a list of all keys, within a given curve order, that can be used with get_coords/1 (linear = 1, quadratic = 2, cubic = 3)

Return details/1 for every predefined curve, sorted by key.

Types

curve_key()

@type curve_key() :: atom()

Cubic

:ease, :ease_in, :ease_out, :ease_in_out, :ease_in_back, :ease_in_circ, :ease_in_cubic, :ease_in_expo, :ease_in_quad, :ease_in_quart, :ease_in_quint, :ease_in_sine, :ease_out_back, :ease_out_circ, :ease_out_cubic, :ease_out_expo, :ease_out_quad, :ease_out_quart, :ease_out_quint, :ease_out_sine, :ease_in_out_back, :ease_in_out_circ, :ease_in_out_cubic, :ease_in_out_expo, :ease_in_out_quad, :ease_in_out_quart, :ease_in_out_quint, :ease_in_out_sine

Quadratic

:quadratic_up, :quadratic_down, :quadratic_left, :quadratic_right

Linear

:linear, :linear_up_right, :linear_down_right, :linear_horizontal, :linear_vertical

curve_keys()

@type curve_keys() :: [curve_key()]

A list of curve keys

curve_type_info()

@type curve_type_info() :: %{
  order: Curves.Types.order(),
  key: curve_key(),
  points: Curves.Types.point_list()
}

A map of useful info about a predefined curve.

curve_type_infos()

@type curve_type_infos() :: [curve_type_info()]

A list of curve type info

Functions

details(k)

@spec details(curve_key()) :: curve_type_info()

Return a map with details about a specific curve.

Examples

iex> Curves.Bezier.Predefined.details(:linear_up_right)
%{key: :linear_up_right, order: 1, points: [{0.0, 0.0}, {1.0, 1.0}]}

get_coords(k)

@spec get_coords(curve_key()) :: Curves.Types.point_list()

Return the list of {x, y} points for a predefined curve. A name that isn't one raises an ArgumentError.

Examples

iex> Curves.Bezier.Predefined.get_coords(:linear_up_right)
[{0.0, 0.0}, {1.0, 1.0}]
iex> Curves.Bezier.Predefined.get_coords(:nope)
** (ArgumentError) unknown predefined curve: :nope. See Curves.Bezier.Predefined.list/0 for the names

list()

@spec list() :: curve_keys()

Return a list of all keys that can be used with get_coords/1

Examples

iex> [:ease | _] = Curves.Bezier.Predefined.list()

list(order)

@spec list(Curves.Types.order() | :linear | :quad | :cubic) :: curve_keys()

Return a list of all keys, within a given curve order, that can be used with get_coords/1 (linear = 1, quadratic = 2, cubic = 3)

alternately, pass in one of :linear, :quad, :cubic.

Examples

iex> [:linear | _] = Curves.Bezier.Predefined.list(1)
iex> [:quadratic_down | _] = Curves.Bezier.Predefined.list(2)
iex> Curves.Bezier.Predefined.list(:cubic) == Curves.Bezier.Predefined.list(3)
true
iex> Curves.Bezier.Predefined.list(:linear) == Curves.Bezier.Predefined.list(1)
true
iex> Curves.Bezier.Predefined.list(:quad) == Curves.Bezier.Predefined.list(2)
true

list_details()

@spec list_details() :: [curve_type_info()]

Return details/1 for every predefined curve, sorted by key.

Examples

iex> [first | _] = Curves.Bezier.Predefined.list_details()
iex> first
%{key: :ease, order: 3, points: [{0.0, 0.0}, {0.3, 0.0}, {0.65, 0.0}, {1.0, 1.0}]}