Interface Curve
- All Known Implementing Classes:
Mapping
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A function from one number to another, usually used to shape
animation progress.
The built-in curves come in three kinds:
LINEARreturns its input unchanged, so it keeps going outside [0, 1].- Easing curves (
SMOOTHSTEP,EASE_IN_QUAD,EASE_IN_CUBIC) are defined on [0, 1] and hold their endpoints outside it: below 0 they return 0, above 1 they return 1. An animation that runs past its end stays at its end. Ease-out and ease-in-out versions come fromflipped()andinOut(). - Repeating curves (
REPEAT,PINGPONG,SINE) complete one cycle per unit of input and return values in [0, 1]. To change the period, use aMapping:Mapping.from(0, 2).through(Curve.SINE)repeats every 2 units. To shift the phase, shift the input:SINE.apply(t + 0.25).
Custom curves can be written as lambdas, such as
Curve cube = t -> t * t * t;. Custom curves are not clamped
unless they clamp their own input.
Curve easeOut = Curve.EASE_IN_QUAD.flipped();
Curve easeInOut = Curve.EASE_IN_CUBIC.inOut();
Curve bounce = Curve.PINGPONG.then(Curve.SMOOTHSTEP);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CurveCubic ease-in: slower start, faster finish than quadratic.static final CurveQuadratic ease-in: slow start, fast finish.static final CurveReturns the input unchanged.static final CurveTriangle wave: rises from 0 to 1 and falls back to 0, once per unit.static final CurveSawtooth wave: rises from 0 toward 1, then jumps back to 0, once per unit.static final CurveSine wave between 0 and 1, once per unit.static final CurveStarts gently, speeds up, then eases to a stop. -
Method Summary
Modifier and TypeMethodDescriptiondoubleapply(double t) Evaluates the curve.default Curveflipped()Rotates this curve 180 degrees around the point (0.5, 0.5), giving1 - f(1 - t).default CurveinOut()Runs this curve at double speed for the first half, then its flipped version for the second half.default CurveRuns this curve first, then feeds its result intonext.
-
Field Details
-
LINEAR
Returns the input unchanged. -
SMOOTHSTEP
Starts gently, speeds up, then eases to a stop. Holds 0 below 0 and 1 above 1. -
EASE_IN_QUAD
Quadratic ease-in: slow start, fast finish. Holds 0 below 0 and 1 above 1. -
EASE_IN_CUBIC
Cubic ease-in: slower start, faster finish than quadratic. Holds 0 below 0 and 1 above 1. -
REPEAT
Sawtooth wave: rises from 0 toward 1, then jumps back to 0, once per unit. -
PINGPONG
Triangle wave: rises from 0 to 1 and falls back to 0, once per unit. -
SINE
Sine wave between 0 and 1, once per unit. Starts at 0.5 and rises.
-
-
Method Details
-
apply
double apply(double t) Evaluates the curve.- Parameters:
t- input value (usually progress from 0 to 1)- Returns:
- curve value
-
then
-
flipped
Rotates this curve 180 degrees around the point (0.5, 0.5), giving1 - f(1 - t). Turns an ease-in into the matching ease-out: fast start, slow finish.Meant for easing curves that go from 0 to 1 over [0, 1]. It works on any curve, including repeating curves and
Mappings, but the result is rarely useful unless the curve runs from 0 to 1.- Returns:
- the flipped curve
-
inOut
Runs this curve at double speed for the first half, then its flipped version for the second half. Turns an ease-in into the matching ease-in-out: slow start, fast middle, slow finish.Meant for easing curves that go from 0 to 1 over [0, 1]. It works on any curve, including repeating curves and
Mappings, but the result is rarely useful unless the curve runs from 0 to 1.- Returns:
- the ease-in-out curve
-