ease

package
v0.0.0-...-20810c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Modifiers = id.NewDenseKeyMap[Modifier, uint16, uint8]()

	In = NewModifier("in", func(easing Fn) Fn {
		return easing
	})
	Out = NewModifier("out", func(easing Fn) Fn {
		return func(x float32) float32 {
			return 1 - easing(1-x)
		}
	})
	InOut = NewModifier("inout", func(easing Fn) Fn {
		return func(x float32) float32 {
			if x < 0.5 {
				return easing(2.0*x) * 0.5
			} else {
				return 1.0 - (easing(2.0-2.0*x) * 0.5)
			}
		}
	})
	YoYo = NewModifier("yoyo", func(easing Fn) Fn {
		return func(x float32) float32 {
			if x < 0.5 {
				return easing(2.0 * x)
			} else {
				return easing(2.0 - 2.0*x)
			}
		}
	})
	Mirror = NewModifier("mirror", func(easing Fn) Fn {
		return func(x float32) float32 {
			if x < 0.5 {
				return easing(2.0 * x)
			} else {
				return 1.0 - easing(2.0-2.0*x)
			}
		}
	})
	Reverse = NewModifier("reverse", func(easing Fn) Fn {
		return func(x float32) float32 {
			return easing(1.0 - x)
		}
	})
	Flip = NewModifier("flip", func(easing Fn) Fn {
		return func(x float32) float32 {
			return 1.0 - easing(x)
		}
	})
)

Modifiers

View Source
var (
	Easings = id.NewDenseKeyMap[Easing, uint16, uint8]()

	Linear = Name("linear", Fn(func(x float32) float32 {
		return x
	}))
	Quad = Name("quad", Fn(func(x float32) float32 {
		return x * x
	}))
	Ease = Name("ease", Fn(func(x float32) float32 {
		i := (1.0 - x)
		i2 := i * i
		x2 := x * x
		eq1 := (0.3 * i2 * x) + (3.0 * i * x2) + (x2 * x)
		eq2 := 1.0 - i2*i2

		return eq1*i + eq2*x
	}))
	Cubic = Name("cubic", Fn(func(x float32) float32 {
		return x * x * x
	}))
	Quartic = Name("quartic", Fn(func(x float32) float32 {
		x2 := x * x
		return x2 * x2
	}))
	Quintic = Name("quintic", Fn(func(x float32) float32 {
		x2 := x * x
		return x2 * x2 * x
	}))
	Back = Name("back", Fn(func(x float32) float32 {
		x2 := x * x
		x3 := x2 * x
		return x3 + x2 - x
	}))
	Sine = Name("sine", Fn(func(x float32) float32 {
		return core.Sin(x * 1.57079632679)
	}))
	Overshot = Name("overshot", Fn(func(x float32) float32 {
		return (1.0 - x*(7.0/10)) * x * (10.0 / 3.0)
	}))
	Elastic = Name("elastic", Fn(func(x float32) float32 {
		x2 := x * x
		x3 := x2 * x
		scale := x2 * ((2.0 * x3) + x2 - (4.0 * x) + 2.0)
		wave := -core.Sin(x * 10.9955742876)
		return scale * wave
	}))
	Revisit = Name("revisit", Fn(func(x float32) float32 {
		return core.Abs(x - core.Sin(x*3.14159265359))
	}))
	Lasso = Name("lasso", Fn(func(x float32) float32 {
		return (1.0 - core.Cos(x*x*x*36.0)*(1.0-x))
	}))
	SlowBounce = Name("slowbounce", Fn(func(x float32) float32 {
		x2 := x * x
		return (1.0 - core.Abs((1.0-x2)*core.Cos(x2*x*14.8044066016)))
	}))
	Bounce = Name("bounce", Fn(func(x float32) float32 {
		return (1.0 - core.Abs((1.0-x)*core.Cos(x*x*14.8044066016)))
	}))
	SmallBounce = Name("smallbounce", Fn(func(x float32) float32 {
		inv := 1.0 - x
		return (1.0 - core.Abs(inv*inv*core.Cos(x*x*14.8044066016)))
	}))
	TinyBounce = Name("tinybounce", Fn(func(x float32) float32 {
		inv := 1.0 - x
		return (1.0 - core.Abs(inv*inv*core.Cos(x*x*7.0)))
	}))
	Hesitant = Name("hesitant", Fn(func(x float32) float32 {
		return (core.Cos(x*x*12.0)*x*(1.0-x) + x)
	}))
	Sqrt = Name("sqrt", Fn(func(x float32) float32 {
		return core.Sqrt(x)
	}))
	Cos = Name("cos", Fn(func(x float32) float32 {
		return 0.5 - core.Cos(x*math.Pi)*0.5
	}))
	Sqrtf = Name("sqrtf", Fn(func(x float32) float32 {
		i := (1.0 - x)
		i2 := i * i
		return ((1.0 - i2*i2) + x) * 0.5
	}))
	Log10 = Name("log10", Fn(func(x float32) float32 {
		return (core.Log10(x+0.01) + 2.0) * 0.5 / 1.0021606868913213
	}))
	Slingshot = Name("slingshot", Fn(func(x float32) float32 {
		if x < 0.7 {
			return (x * -0.357)
		} else {
			d := x - 0.7
			return ((d*d*27.5 - 0.5) * 0.5)
		}
	}))
	Circular = Name("circular", Fn(func(x float32) float32 {
		return 1.0 - core.Sqrt(1-x*x)
	}))
	Gentle = Name("gentle", Fn(func(x float32) float32 {
		return (3.0 * (1.0 - x) * x * x) + (x * x * x)
	}))

	// CSS easing functions
	CssEase      = Name("cssease", Ease)
	CssEaseIn    = Name("csseasein", Quad)
	CssEaseOut   = Name("csseaseout", Out.Modify(Quad))
	CssEaseInOut = Name("csseaseinout", InOut.Modify(Quad))
	CssLinear    = Name("csslinear", Linear)
)

Easings

View Source
var Regex = regexp.MustCompile(`^(?i)(bezier\(\s*(-?\d*\.?\d*)\s*,\s*(-?\d*\.?\d*)\s*,\s*(-?\d*\.?\d*)\s*,\s*(-?\d*\.?\d*)\s*\)|([^-]*))(|\s*-\s*([^*]+))(|\s*\*\s*(-?\d*\.?\d*))`)

Formats: easing easing-modifier easing*scale easing-modifier*scale bezier(mx1,my1,mx2,my2) bezier(mx1,my1,mx2,my2)*scale

Functions

func Add

func Add(easing Easing)

func AddModifier

func AddModifier(modifier Modifier)

func Get

func Get(x float32, easing Easing) float32

func NameOf

func NameOf(easing Easing) id.Identifier

func StringOf

func StringOf(easing Easing) string

Types

type Bezier

type Bezier struct {
	MX1, MY1, MX2, MY2 float32
}

func NewBezier

func NewBezier(MX1, MY1, MX2, MY2 float32) Bezier

func (Bezier) A

func (b Bezier) A(aA1, aA2 float32) float32

func (Bezier) B

func (b Bezier) B(aA1, aA2 float32) float32

func (Bezier) C

func (b Bezier) C(aA1 float32) float32

func (Bezier) CalcBezier

func (b Bezier) CalcBezier(aT, aA1, aA2 float32) float32

func (Bezier) Ease

func (b Bezier) Ease(x float32) float32

func (Bezier) GetSlope

func (b Bezier) GetSlope(aT, aA1, aA2 float32) float32

func (Bezier) GetTForX

func (b Bezier) GetTForX(aX float32) float32

func (Bezier) Name

func (b Bezier) Name() id.Identifier

func (Bezier) String

func (b Bezier) String() string

type Easing

type Easing interface {
	Ease(x float32) float32
	Name() id.Identifier
	String() string
}

func MustParse

func MustParse(s string) Easing

func Name

func Name(name string, easing Easing) Easing

func Parse

func Parse(s string) (Easing, error)

type Fn

type Fn func(x float32) float32

func (Fn) Ease

func (fn Fn) Ease(x float32) float32

func (Fn) Name

func (fn Fn) Name() id.Identifier

func (Fn) String

func (fn Fn) String() string

type Modified

type Modified struct {
	Modifier Modifier
	Easing   Easing
	Fn       Fn
}

func (Modified) Ease

func (m Modified) Ease(x float32) float32

func (Modified) Name

func (m Modified) Name() id.Identifier

func (Modified) String

func (m Modified) String() string

type Modifier

type Modifier struct {
	Fn   ModifierFn
	Name id.Identifier
}

func NewModifier

func NewModifier(name string, fn ModifierFn) Modifier

func (Modifier) Modify

func (m Modifier) Modify(easing Easing) Modified

type ModifierFn

type ModifierFn func(easing Fn) Fn

type Named

type Named struct {
	// contains filtered or unexported fields
}

func (Named) Ease

func (en Named) Ease(x float32) float32

func (Named) Name

func (en Named) Name() id.Identifier

func (Named) String

func (en Named) String() string

type Scaled

type Scaled struct {
	Scale  float32
	Easing Easing
}

func (Scaled) Ease

func (s Scaled) Ease(x float32) float32

func (Scaled) Name

func (s Scaled) Name() id.Identifier

func (Scaled) String

func (s Scaled) String() string

type Subset

type Subset struct {
	Easing     Easing
	Start, End float32
	// contains filtered or unexported fields
}

func NewSubset

func NewSubset(easing Easing, start, end float32) Subset

func (Subset) Ease

func (s Subset) Ease(x float32) float32

func (Subset) Name

func (s Subset) Name() id.Identifier

func (Subset) String

func (s Subset) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL