Skip to content

Timing & easing functions PHP nano library - EaseIn, EaseOut, CubicBezier ...

License

Notifications You must be signed in to change notification settings

smnandre/easing-functions

Repository files navigation

Easing & Timing PHP Functions

Easing Functions

composer require smnandre/easing-functions

PHP Version CI Release License Codecov


EasingFunctions is a PHP library that provides a collection of easing functions commonly used in animations, transitions, and smooth interpolations.

It includes standard easing equations: quadratic, cubic, quartic, quintic, sine, exponential, circular, elastic, and bounce functions.

Each of them is available in three variations:

  • In: The motion starts slowly and accelerates.
  • Out: The motion starts quickly and decelerates.
  • InOut: A combination of both, accelerating at the start and decelerating at the end.

Easing Functions

x In InOut Out
Cubic Ease In Cubic
easeInCubic
Ease Out Cubic
easeOutCubic
Ease InOut Cubic
easeInOutCubic
Quart Ease In Quart
easeInQuart
Ease Out Quart
easeOutQuart
Ease InOut Quart
easeInOutQuart
Quad Ease In Quad
easeInQuad
Ease Out Quad
easeOutQuad
Ease InOut Quad
easeInOutQuad
Quint Ease In Quint
easeInQuint
Ease Out Quint
easeOutQuint
Ease InOut Quint
easeInOutQuint
Sine Ease In Sine
easeInSine
Ease Out Sine
easeOutSine
Ease InOut Sine
easeInOutSine
Expo Ease In Expo
easeInExpo
Ease Out Expo
easeOutExpo
Ease InOut Expo
easeInOutExpo
Circ Ease In Circ
easeInCirc
Ease Out Circ
easeOutCirc
Ease InOut Circ
easeInOutCirc
Back Ease In Back
easeInBack
Ease Out Back
easeOutBack
Ease InOut Back
easeInOutBack
Bounce Ease In Bounce
easeInBounce
Ease Out Bounce
easeOutBounce
Ease InOut Bounce
easeInOutBounce
Elastic Ease In Elastic
easeInElastic
Ease Out Elastic
easeOutElastic
Ease InOut Elastic
easeInOutElastic

Installation

composer require smnandre/easing-functions

Usage

Easing\Functions::easeOutCubic(0);
// 0
Easing\Functions::easeOutCubic(0.5);
// 0.875

$values = array_map(Easing\Functions::easeOutCubic(...), range(0, 1, 0.1));
echo implode(" ", $values);
// 0 0.271 0.488 0.657 0.784 0.875 0.936 0.973 0.992 0.999 1

Functions

Easing Functions

Name Formulae Preview
easeOutCubic $1 - pow(1 - x, 3)$ easeOutCubic PHP
easeInOutCubic $x < 0.5 ? 4 * pow(x, 3) : 1 - pow(-2 * x + 2, 3) / 2$ easeInOutCubic PHP
easeInQuart $pow(x, 4)$ easeInQuart PHP
easeOutQuart $1 - pow(1 - x, 4)$ easeOutQuart PHP
easeInOutQuart $x < 0.5 ? 8 * pow(x, 4) : 1 - pow(-2 * x + 2, 4) / 2$ easeInOutQuart PHP
easeInCubic $pow(x, 3)$ easeInCubic PHP
easeInQuad $x * x$ easeInQuad PHP
easeOutQuad $1 - (1 - x) * (1 - x)$ easeOutQuad PHP
easeInOutQuad $x < 0.5 ? 2 * x * x : 1 - pow(-2 * x + 2, 2) / 2$ easeInOutQuad PHP
easeInQuint $pow(x, 5)$ easeInQuint PHP
easeOutQuint $1 - pow(1 - x, 5)$ easeOutQuint PHP
easeInOutQuint $x < 0.5 ? 16 * pow(x, 5) : 1 - pow(-2 * x + 2, 5) / 2$ easeInOutQuint PHP
easeInSine $1 - cos((x * pi()) / 2)$ easeInSine PHP
easeOutSine $sin((x * pi()) / 2)$ easeOutSine PHP
easeInOutSine $-(cos(pi() * x) - 1) / 2$ easeInOutSine PHP
easeInExpo $x == 0 ? 0 : pow(2, 10 * x - 10)$ easeInExpo PHP
easeOutExpo $x == 1 ? 1 : 1 - pow(2, -10 * x)$ easeOutExpo PHP
easeInOutExpo $x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? pow(2, 20 * x - 10) / 2 : (2 - pow(2, -20 * x + 10)) / 2$ easeInOutExpo PHP
easeInCirc $1 - sqrt(1 - pow(x, 2))$ easeInCirc PHP
easeOutCirc $sqrt(1 - pow(x - 1, 2))$ easeOutCirc PHP
easeInOutCirc $x < 0.5 ? (1 - sqrt(1 - pow(2 * x, 2))) / 2 : (sqrt(1 - pow(-2 * x + 2, 2)) + 1) / 2$ easeInOutCirc PHP
easeInBack $2.70158 * pow(x, 3) - 1.70158 * pow(x, 2)$ easeInBack PHP
easeOutBack $1 + 2.70158 * pow(x - 1, 3) + 1.70158 * pow(x - 1, 2)$ easeOutBack PHP
easeInOutBack $x < 0.5 ? (pow(2 * x, 2) * ((3.59258 * 2 * x) - 2.59258)) / 2 : (pow(2 * x - 2, 2) * ((3.59258 * (x * 2 - 2)) + 2.59258) + 2) / 2$ easeInOutBack PHP
easeInBounce $1 - easeOutBounce(1 - x)$ easeInBounce PHP
easeOutBounce See bounceOut function easeOutBounce PHP
easeInOutBounce $x < 0.5 ? (1 - easeOutBounce(1 - 2 * x)) / 2 : (1 + easeOutBounce(2 * x - 1)) / 2$ easeInOutBounce PHP
easeInElastic $x == 0 ? 0 : x == 1 ? 1 : -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * ((2 * pi()) / 3))$ easeInElastic PHP
easeOutElastic $x == 0 ? 0 : x == 1 ? 1 : pow(2, -10 * x) * sin((x * 10 - 0.75) * ((2 * pi()) / 3)) + 1$ easeOutElastic PHP
easeInOutElastic $x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? -(pow(2, 20 * x - 10) * sin((20 * x - 11.125) * ((2 * pi()) / 4.5))) / 2 : (pow(2, -20 * x + 10) * sin((20 * x - 11.125) * ((2 * pi()) / 4.5))) / 2 + 1$ easeInOutElastic PHP

License

This project is licensed under the MIT License. See the LICENSE file for more information.