A collection of cross-platform easing functions written in Swift with no dependencies on SwiftUI or CoreGraphics.
// An ease-out curve
let unitCurve = EaseOutInEaseOut()
let unitY = unitCurve.value(at: 0.88)
Type | EaseIn |
EaseOut |
EaseInEaseOut |
---|---|---|---|
sine |
![]() |
![]() |
![]() |
cubic |
![]() |
![]() |
![]() |
quint |
![]() |
![]() |
![]() |
circ |
![]() |
![]() |
![]() |
quad |
![]() |
![]() |
![]() |
quart |
![]() |
![]() |
![]() |
expo |
![]() |
![]() |
![]() |
bounce |
![]() |
![]() |
![]() |
back |
![]() |
![]() |
![]() |
elastic |
![]() |
![]() |
![]() |
// An ease-out curve
let unitCurve = EaseOut(.cubic)
let unitY = unitCurve.value(at: 0.25)
// An ease-in-ease-out elastic curve
let unitY = easeInEaseOutElastic(at: 0.68)
A Cubic bezier curve with the first point P0
as (0.0, 0.0) and last point P3
as (1.0, 1.0).
A cubic Bézier curve is defined by four points: P0, P1, P2, and P3. The points P0 and P3 represent the start and the end of the curve
Cubic Bézier curves with the P1 or P2 coordinate outside the [0, 1] range can cause the value to go farther than the final state and then return.
let unitCurve = CubicBezierCurve(x1: 0.1, y1: 0.6, x2: 0.7, y2: 0.2)
let unitY = unitCurve.value(at: 0.25)
Linear curves define the Y
values equally spaced along the t axis.
A linear curve must always start at 0.0 and end at 1.0.
let linear = Linear(values: [0.0, 0.25, 0.25, 1.0])
let unitY = linear.value(at: 0.25)
// An linear curve
let linear = Linear(values: [0.0, 0.1, 0.5, 0.9, 1.0])
let unitY = linear.value(at: 0.68)
Jump curves define step function(s) that divides the domain of output values in equidistant steps
let jump = Jump(.jumpEnd, steps: 4)
let unitY = jump.value(at: 0.25)
let jump = Jump(.jumpBoth, steps: 3)
let unitY = jump.value(at: 0.68)
- Robert Penner archived
- Nic Mulvaney archived
- Steps easing functions @ Mozilla
- Cubic Bézier easing functions @ Mozilla
MIT License
Copyright (c) 2024 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Easing terms of use (archive.org)
MIT License
Copyright © 2001 Robert Penner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.