Package com.formdev.flatlaf.util
Class CubicBezierEasing
- java.lang.Object
-
- com.formdev.flatlaf.util.CubicBezierEasing
-
- All Implemented Interfaces:
Animator.Interpolator
public class CubicBezierEasing extends java.lang.Object implements Animator.Interpolator
An interpolator forAnimator
that uses a cubic bezier curve.
-
-
Field Summary
Fields Modifier and Type Field Description static CubicBezierEasing
EASE
static CubicBezierEasing
EASE_IN
static CubicBezierEasing
EASE_IN_OUT
static CubicBezierEasing
EASE_OUT
static CubicBezierEasing
STANDARD_EASING
Standard easing as specified in Material design (0.4, 0, 0.2, 1).private float
x1
private float
x2
private float
y1
private float
y2
-
Constructor Summary
Constructors Constructor Description CubicBezierEasing(float x1, float y1, float x2, float y2)
Creates a cubic bezier easing interpolator with the given control points.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static float
cubicBezier(float t, float xy1, float xy2)
Computes the x or y point on a cubic bezier curve for a given t value.float
interpolate(float fraction)
Interpolate the given fraction and returns a new fraction.
-
-
-
Field Detail
-
STANDARD_EASING
public static final CubicBezierEasing STANDARD_EASING
Standard easing as specified in Material design (0.4, 0, 0.2, 1).
-
EASE
public static final CubicBezierEasing EASE
-
EASE_IN
public static final CubicBezierEasing EASE_IN
-
EASE_IN_OUT
public static final CubicBezierEasing EASE_IN_OUT
-
EASE_OUT
public static final CubicBezierEasing EASE_OUT
-
x1
private final float x1
-
y1
private final float y1
-
x2
private final float x2
-
y2
private final float y2
-
-
Constructor Detail
-
CubicBezierEasing
public CubicBezierEasing(float x1, float y1, float x2, float y2)
Creates a cubic bezier easing interpolator with the given control points. The start point of the cubic bezier curve is always 0,0 and the end point 1,1.- Parameters:
x1
- the x coordinate of the first control point in range [0, 1]y1
- the y coordinate of the first control point in range [0, 1]x2
- the x coordinate of the second control point in range [0, 1]y2
- the y coordinate of the second control point in range [0, 1]
-
-
Method Detail
-
interpolate
public float interpolate(float fraction)
Description copied from interface:Animator.Interpolator
Interpolate the given fraction and returns a new fraction. Both fractions are in range [0, 1].- Specified by:
interpolate
in interfaceAnimator.Interpolator
- Parameters:
fraction
- the percent (0 to 1) elapsed of the current animation cycle- Returns:
- new fraction in range [0, 1]
-
cubicBezier
private static float cubicBezier(float t, float xy1, float xy2)
Computes the x or y point on a cubic bezier curve for a given t value. https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves The general cubic bezier formula is: x = b0*x0 + b1*x1 + b2*x2 + b3*x3 y = b0*y0 + b1*y1 + b2*y2 + b3*y3 where: b0 = (1-t)^3 b1 = 3 * t * (1-t)^2 b2 = 3 * t^2 * (1-t) b3 = t^3 x0,y0 is always 0,0 and x3,y3 is 1,1, so we can simplify to: x = b1*x1 + b2*x2 + b3 y = b1*x1 + b2*x2 + b3
-
-