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.

@FunctionalInterface public interface Curve
A function from one number to another, usually used to shape animation progress.

The built-in curves come in three kinds:

  • LINEAR returns 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 from flipped() and inOut().
  • Repeating curves (REPEAT, PINGPONG, SINE) complete one cycle per unit of input and return values in [0, 1]. To change the period, use a Mapping: 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

    Fields
    Modifier and Type
    Field
    Description
    static final Curve
    Cubic ease-in: slower start, faster finish than quadratic.
    static final Curve
    Quadratic ease-in: slow start, fast finish.
    static final Curve
    Returns the input unchanged.
    static final Curve
    Triangle wave: rises from 0 to 1 and falls back to 0, once per unit.
    static final Curve
    Sawtooth wave: rises from 0 toward 1, then jumps back to 0, once per unit.
    static final Curve
    Sine wave between 0 and 1, once per unit.
    static final Curve
    Starts gently, speeds up, then eases to a stop.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    apply(double t)
    Evaluates the curve.
    default Curve
    Rotates this curve 180 degrees around the point (0.5, 0.5), giving 1 - f(1 - t).
    default Curve
    Runs this curve at double speed for the first half, then its flipped version for the second half.
    default Curve
    then(Curve next)
    Runs this curve first, then feeds its result into next.
  • Field Details

    • LINEAR

      static final Curve LINEAR
      Returns the input unchanged.
    • SMOOTHSTEP

      static final Curve SMOOTHSTEP
      Starts gently, speeds up, then eases to a stop. Holds 0 below 0 and 1 above 1.
    • EASE_IN_QUAD

      static final Curve EASE_IN_QUAD
      Quadratic ease-in: slow start, fast finish. Holds 0 below 0 and 1 above 1.
    • EASE_IN_CUBIC

      static final Curve EASE_IN_CUBIC
      Cubic ease-in: slower start, faster finish than quadratic. Holds 0 below 0 and 1 above 1.
    • REPEAT

      static final Curve REPEAT
      Sawtooth wave: rises from 0 toward 1, then jumps back to 0, once per unit.
    • PINGPONG

      static final Curve PINGPONG
      Triangle wave: rises from 0 to 1 and falls back to 0, once per unit.
    • SINE

      static final Curve 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

      default Curve then(Curve next)
      Runs this curve first, then feeds its result into next.

      Order matters: PINGPONG.then(SMOOTHSTEP) eases each bounce, while SMOOTHSTEP.then(PINGPONG) is a different curve entirely.

      Parameters:
      next - curve to apply after this one
      Returns:
      the combined curve
    • flipped

      default Curve flipped()
      Rotates this curve 180 degrees around the point (0.5, 0.5), giving 1 - 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

      default 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