Skip to content

Commit 5dc356f

Browse files
committed
Update README.md
1 parent b1e4d2d commit 5dc356f

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
<p align="center">
22
<img src="Readme/logo.png" width="50%" alt="Easing Logo" />
33
</p>
4-
Easing library is a comprehensive set of easing functions, useful for interactive animations and other time-based calculations where smooth transitions are necessary.
4+
The Easing library is a comprehensive set of easing functions, useful for interactive transitions and other time-based calculations.
55

66
## Features
77

8-
- Unified set of easing functions
8+
- Unified [set](#reference) of easing functions ([])
99
- Easy-to-use 'swifty' API to invoke calculations
10-
- Interpolation shorthands for the most popular primitive types like CGPoint, CGSize, CGTransform, UIColor and UIBezierPath
11-
- Bridge to CAMediaTimingFunction
12-
- Arbitrary cubic bezier based easings
10+
- Interpolation shorthands for commonly used types like `CGPoint`, `CGSize`, `CGTransform`, `UIColor` and `UIBezierPath`
11+
- Arbitrary cubic bezier based easings (see `.cubicBezier(...)`)
12+
- Emulate default easings from iOS (see `.caEaseIn`, `.caEaseOut`, `.caEaseInEaseOut`)
1313
- Interactive demo app
1414
- Supports iOS 12.0+ / Mac OS X 10.13+ / tvOS 12.0+ / watchOS 4.0+ / visionOS 1.0+
1515

1616
## Usage
1717

18+
### Basic
19+
20+
````swift
21+
22+
let startValue = 20.0
23+
let endValue = 60.0
24+
let progress = 0.5 // Assume a progress variable that ranges from 0 to 1
25+
26+
let valueAtProgress = Easing.cubicEaseIn.calculate(
27+
d1: startValue,
28+
d2: endValue,
29+
g: progress
30+
)
31+
````
32+
1833
### Real world example
1934

2035
Imagine an interaction with a `UIScrollView` where its header is fully visible when the content offset is zero and fades out completely as the content offset exceeds 100 points. You can express this behavior with the following code in your `scrollViewDidScroll` method:
@@ -40,8 +55,11 @@ headerView.alpha = Easing.quadraticEaseInOut.calculate(
4055
````swift
4156
let startTransform = CGAffineTransform.identity
4257
let endTransform = CGAffineTransform(scaleX: 2, y: 2)
58+
let progress = 0.5 // Assume a progress variable that ranges from 0 to 1
4359

44-
transformDemoView.transform = startTransform.interpolate(to: endTransform, progress: progress, easing: .linear)
60+
view.transform = startTransform.interpolate(to: endTransform,
61+
progress: progress,
62+
easing: .linear)
4563

4664
````
4765

@@ -111,7 +129,7 @@ https://github.com/psharanda/Easing.git
111129

112130
## References
113131

114-
The main set of easing functions is a Swift port of https://github.com/warrenm/AHEasing which is a port of https://github.com/ai/easings.net (https://easings.net)
132+
The main set of easing functions is a Swift port of https://github.com/warrenm/AHEasing and https://github.com/ai/easings.net
115133

116134
`CubicBezierInterpolator` is a Swift port of `nsSMILKeySpline` code from Mozilla https://github.com/mozilla-services/services-central-legacy/blob/master/content/smil/nsSMILKeySpline.cpp
117135

Sources/Easing/Easing.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public enum Easing {
7171
/**
7272
Calculate d value for g, where g1 = g1, d1 = d1, g2 = g2, d2 = d2
7373
*/
74-
public func calculate(
75-
g1: Double, d1: Double, g2: Double, d2: Double, g: Double, clamp: Bool = true
76-
) -> Double {
74+
public func calculate(g1: Double, d1: Double, g2: Double, d2: Double, g: Double, clamp: Bool = true) -> Double {
7775
var g = g
7876

7977
if clamp {
@@ -163,7 +161,7 @@ public enum Easing {
163161
}
164162
}
165163

166-
// Based on https://github.com/warrenm/AHEasing and https://github.com/ai/easings.net (https://easings.net)
164+
// Based on https://github.com/warrenm/AHEasing and https://github.com/ai/easings.net
167165

168166
// Modeled after the line y = x
169167
private static func _linear(_ p: Double) -> Double {

0 commit comments

Comments
 (0)