animation/bezier.go

Functions

Functions

func CubicBezier

CubicBezier creates an Easing function from cubic bezier control points.

 

The control points define a CSS-style cubic-bezier(x1, y1, x2, y2) curve.

The curve starts at (0,0) and ends at (1,1). x1 and x2 should be in [0,1].

 

Example:

 

ease := animation.CubicBezier(0.25, 0.1, 0.25, 1.0) // CSS "ease"

func CubicBezier(x1, y1, x2, y2 float32) Easing {
	curve := newCubicBezierCurve(x1, y1, x2, y2)
	return curve.Evaluate
}

func Evaluate

Evaluate returns the easing value for the given normalized time x in [0,1].

func (c *cubicBezierCurve) Evaluate(x float32) float32 {
	if x <= 0 {
		return 0
	}
	if x >= 1 {
		return 1
	}
	// Special case: linear bezier.
	if c.x1 == c.y1 && c.x2 == c.y2 {
		return x
	}
	t := c.findT(x)
	return c.calcY(t)
}