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 Functions

composer require smnandre/easing-functions

PHP Version CI Release License Codecov


EasingFunctions is a PHP library that provides easing functions for animations, transitions, etc/

x In InOut Out
Cubic Ease In Cubic
easeInCubic
Ease InOut Cubic
easeInOutCubic
Ease Out Cubic
easeOutCubic
Quart Ease In Quart
easeInQuart
Ease InOut Quart
easeInOutQuart
Ease Out Quart
easeOutQuart
Quad Ease In Quad
easeInQuad
Ease InOut Quad
easeInOutQuad
Ease Out Quad
easeOutQuad

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

Time Comparison

Function 12.5% 25% 37.5% 50% 62.5% 75% 87.5%
OutQuart ██ ███▎ ████ ████▌ ████▊ ████▊ ████▊
OutCubic █▌ ██▊ ███▊ ████▎ ████▌ ████▊ ████▊
OutQuad ██ ███ ███▊ ████▎ ████▌ ████▊
InOutQuad █▎ ██▌ ███▌ ████▎ ████▊
InOutCubic ██▌ ███▊ ████▌ ████▊
InOutQuart ██▌ ████ ████▊ ████▊
InQuad █▎ █▊ ██▊ ███▊
InCubic ██ ███▎
InQuart █▌ ██▊

License

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