https://github.com/setanarut/tween
Tweening package for Go
https://github.com/setanarut/tween
easing easing-curves easing-functions go golang tween tween-animation tweening tweening-library
Last synced: 19 days ago
JSON representation
Tweening package for Go
- Host: GitHub
- URL: https://github.com/setanarut/tween
- Owner: setanarut
- License: mit
- Created: 2025-05-21T22:44:54.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-05-21T23:23:14.000Z (9 months ago)
- Last Synced: 2025-05-22T00:32:39.766Z (9 months ago)
- Topics: easing, easing-curves, easing-functions, go, golang, tween, tween-animation, tweening, tweening-library
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tween [](http://godoc.org/github.com/setanarut/tween)
Tween is a small library to perform [tweening](https://en.wikipedia.org/wiki/Tweening) in Go. It has a minimal
interface, and it comes with several easing functions.
## Quick start
Tween usage
```Go
func main() {
// tween from 0 to 1 in 3 seconds
tw := tween.NewTween(0, 1, 3*time.Second, tween.Linear, false)
// advance by 1.5 seconds
tw.Update(time.Millisecond * 1500)
// get tween value at 1.5 seconds
fmt.Println(tw.Value) // 0.5
// merge multiple tweens into a sequence
sequence := tween.NewSequence(
tween.NewTween(0, 100, 3*time.Second, tween.InCubic, false),
tween.NewTween(100, 40, 2*time.Second, tween.OutCubic, false),
tween.NewTween(4, 100, 20*time.Second, tween.InOutBounce, false),
)
// advance by 7.5 seconds
sequence.Update(time.Millisecond * 7500)
// get sequence value at 7.5 seconds
fmt.Println(sequence.Value) // 5.3125
}
```
See [examples](./examples/) folder for more examples.
## Easing functions
Easing functions are functions that express how slow/fast the interpolation happens in tween.

The easing functions can be found in the `ease` package.
They can be divided into several families:
* `linear` is the simplest easing function, straight from one value to the other.
* `quad`, `cubic`, `quart`, `quint`, `expo`, `sine` and `circle` are all "smooth" curves that will make transitions look natural.
* The `back` family starts by moving the interpolation slightly "backwards" before moving it forward.
* The `bounce` family simulates the motion of an object bouncing.
* The `elastic` family simulates inertia in the easing, like an elastic gum.
Each family (except `linear`) has 4 variants:
* `In` starts slow, and accelerates at the end
* `Out` starts fast, and decelerates at the end
* `InOut` starts and ends slow, but it's fast in the middle
* `OutIn` starts and ends fast, but it's slow in the middle
| family | in | out | inOut | outIn |
| ----------- | --------- | ---------- | ------------ | ------------ |
| **Linear** | Linear | Linear | Linear | Linear |
| **Quad** | InQuad | OutQuad | InOutQuad | OutInQuad |
| **Cubic** | InCubic | OutCubic | InOutCubic | OutInCubic |
| **Quart** | InQuart | OutQuart | InOutQuart | OutInQuart |
| **Quint** | InQuint | OutQuint | InOutQuint | OutInQuint |
| **Expo** | InExpo | OutExpo | InOutExpo | OutInExpo |
| **Sine** | InSine | OutSine | InOutSine | OutInSine |
| **Circ** | InCirc | OutCirc | InOutCirc | OutInCirc |
| **Back** | InBack | OutBack | InOutBack | OutInBack |
| **Bounce** | InBounce | OutBounce | InOutBounce | OutInBounce |
| **Elastic** | InElastic | OutElastic | InOutElastic | OutInElastic |