Macaw.Draw.Ease (macaw_draw v0.1.0)

Copy Markdown View Source

The 25 easing curves (spec/07 §18), copied from visualize's Visualize.Ease: functions from t in [0, 1] to a float, nominally in [0, 1] (the elastic_* and back_* families overshoot).

iex> Macaw.Draw.Ease.quad_in(0.5)
0.25
iex> {:ok, ease} = Macaw.Draw.Ease.by_name("cubic_in_out")
iex> ease.(0.5)
0.5

The exact-endpoint clauses match the integer literals 0 and 1 only; the floats 0.0 and 1.0 take the formula (exp_in(0.0) is 2^−10). by_name/1 reads a name by spelling and refuses an unknown one as {[], {:unknown, :ease, spelling}}, where visualize raised; frames/2 samples a curve at evenly spaced t.

Every easing answers a value for any number: a t that is no number is {[], {:type, :number}}, and one outside [0, 1] where the curve is undefined or past a float's range (a circle's square root of a negative, an exponential's overflow) is {[], {:domain, t}}.

Summary

Types

A refusal: faults with their paths.

Functions

The back_in easing of t (spec/07 §18).

back_in with the overshoot s in place of 1.70158.

The back_in_out easing of t (spec/07 §18).

The back_out easing of t (spec/07 §18).

back_out with the overshoot s in place of 1.70158.

The bounce_in easing of t (spec/07 §18).

The bounce_in_out easing of t (spec/07 §18).

The bounce_out easing of t (spec/07 §18).

The easing of a name, an atom or its string read by spelling: {:ok, fun}, or {:error, [{[], {:unknown, :ease, spelling}}]}.

The circle_in easing of t (spec/07 §18).

The circle_in_out easing of t (spec/07 §18).

The circle_out easing of t (spec/07 §18).

The cubic_in easing of t (spec/07 §18).

The cubic_in_out easing of t (spec/07 §18).

The cubic_out easing of t (spec/07 §18).

The elastic_in easing of t (spec/07 §18).

The elastic_in_out easing of t (spec/07 §18).

The elastic_out easing of t (spec/07 §18).

The exp_in easing of t (spec/07 §18).

The exp_in_out easing of t (spec/07 §18).

The exp_out easing of t (spec/07 §18).

count values of an easing, named or a 1-arity function, at t = i / (count − 1) for i in 0..count − 1 when count > 1, and [1.0] for a count of 1 or less; {:error, faults} for an unknown name.

The linear easing of t (spec/07 §18).

The 25 names, in spec/07 §18's order.

t^e, exponent 3 by default.

2^(e−1)·t^e below one half, else 1 − (−2t + 2)^e / 2; exponent 3 by default.

1 − (1 − t)^e, exponent 3 by default.

The quad_in easing of t (spec/07 §18).

The quad_in_out easing of t (spec/07 §18).

The quad_out easing of t (spec/07 §18).

The sin_in easing of t (spec/07 §18).

The sin_in_out easing of t (spec/07 §18).

The sin_out easing of t (spec/07 §18).

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

Functions

back_in(t)

@spec back_in(number()) :: float() | error()

The back_in easing of t (spec/07 §18).

back_in(t, s)

@spec back_in(number(), number()) :: float() | error()

back_in with the overshoot s in place of 1.70158.

back_in_out(t)

@spec back_in_out(number()) :: float() | error()

The back_in_out easing of t (spec/07 §18).

back_out(t)

@spec back_out(number()) :: float() | error()

The back_out easing of t (spec/07 §18).

back_out(t, s)

@spec back_out(number(), number()) :: float() | error()

back_out with the overshoot s in place of 1.70158.

bounce_in(t)

@spec bounce_in(number()) :: float() | error()

The bounce_in easing of t (spec/07 §18).

bounce_in_out(t)

@spec bounce_in_out(number()) :: float() | error()

The bounce_in_out easing of t (spec/07 §18).

bounce_out(t)

@spec bounce_out(number()) :: float() | error()

The bounce_out easing of t (spec/07 §18).

by_name(name)

@spec by_name(term()) :: {:ok, (number() -> term())} | error()

The easing of a name, an atom or its string read by spelling: {:ok, fun}, or {:error, [{[], {:unknown, :ease, spelling}}]}.

circle_in(t)

@spec circle_in(number()) :: float() | error()

The circle_in easing of t (spec/07 §18).

circle_in_out(t)

@spec circle_in_out(number()) :: float() | error()

The circle_in_out easing of t (spec/07 §18).

circle_out(t)

@spec circle_out(number()) :: float() | error()

The circle_out easing of t (spec/07 §18).

cubic_in(t)

@spec cubic_in(number()) :: float() | error()

The cubic_in easing of t (spec/07 §18).

cubic_in_out(t)

@spec cubic_in_out(number()) :: float() | error()

The cubic_in_out easing of t (spec/07 §18).

cubic_out(t)

@spec cubic_out(number()) :: float() | error()

The cubic_out easing of t (spec/07 §18).

elastic_in(t)

@spec elastic_in(number()) :: float() | error()

The elastic_in easing of t (spec/07 §18).

elastic_in_out(t)

@spec elastic_in_out(number()) :: float() | error()

The elastic_in_out easing of t (spec/07 §18).

elastic_out(t)

@spec elastic_out(number()) :: float() | error()

The elastic_out easing of t (spec/07 §18).

exp_in(t)

@spec exp_in(number()) :: float() | error()

The exp_in easing of t (spec/07 §18).

exp_in_out(t)

@spec exp_in_out(number()) :: float() | error()

The exp_in_out easing of t (spec/07 §18).

exp_out(t)

@spec exp_out(number()) :: float() | error()

The exp_out easing of t (spec/07 §18).

frames(ease, count)

@spec frames(term(), integer()) :: [term()] | error()

count values of an easing, named or a 1-arity function, at t = i / (count − 1) for i in 0..count − 1 when count > 1, and [1.0] for a count of 1 or less; {:error, faults} for an unknown name.

linear(t)

@spec linear(number()) :: float() | error()

The linear easing of t (spec/07 §18).

names()

@spec names() :: [atom()]

The 25 names, in spec/07 §18's order.

poly_in(t, exponent \\ 3)

@spec poly_in(number(), number()) :: float() | error()

t^e, exponent 3 by default.

poly_in_out(t, exponent \\ 3)

@spec poly_in_out(number(), number()) :: float() | error()

2^(e−1)·t^e below one half, else 1 − (−2t + 2)^e / 2; exponent 3 by default.

poly_out(t, exponent \\ 3)

@spec poly_out(number(), number()) :: float() | error()

1 − (1 − t)^e, exponent 3 by default.

quad_in(t)

@spec quad_in(number()) :: float() | error()

The quad_in easing of t (spec/07 §18).

quad_in_out(t)

@spec quad_in_out(number()) :: float() | error()

The quad_in_out easing of t (spec/07 §18).

quad_out(t)

@spec quad_out(number()) :: float() | error()

The quad_out easing of t (spec/07 §18).

sin_in(t)

@spec sin_in(number()) :: float() | error()

The sin_in easing of t (spec/07 §18).

sin_in_out(t)

@spec sin_in_out(number()) :: float() | error()

The sin_in_out easing of t (spec/07 §18).

sin_out(t)

@spec sin_out(number()) :: float() | error()

The sin_out easing of t (spec/07 §18).