{"id":18745142,"url":"https://github.com/tanema/gween","last_synced_at":"2025-04-12T21:32:42.341Z","repository":{"id":26053132,"uuid":"107211877","full_name":"tanema/gween","owner":"tanema","description":"Tween animation library for go with a simple interface.","archived":false,"fork":false,"pushed_at":"2024-02-06T02:31:10.000Z","size":52,"stargazers_count":90,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T15:54:31.826Z","etag":null,"topics":["easing-functions","golang","golang-library","tween","tweening"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanema.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-17T03:14:10.000Z","updated_at":"2025-03-20T22:57:04.000Z","dependencies_parsed_at":"2024-06-18T17:08:48.336Z","dependency_job_id":"6a2412d8-b64c-40dc-9da2-f661ae1a44ed","html_url":"https://github.com/tanema/gween","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanema%2Fgween","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanema%2Fgween/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanema%2Fgween/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanema%2Fgween/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanema","download_url":"https://codeload.github.com/tanema/gween/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636274,"owners_count":21137412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easing-functions","golang","golang-library","tween","tweening"],"created_at":"2024-11-07T16:17:02.082Z","updated_at":"2025-04-12T21:32:42.036Z","avatar_url":"https://github.com/tanema.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gween [![](https://godoc.org/github.com/tanema/gween?status.svg)](http://godoc.org/github.com/tanema/gween)\n\nGween (go-between) is a small library to perform [tweening](http://en.wikipedia.org/wiki/Tweening) in Go. It has a minimal\ninterface, and it comes with several easing functions.\n\n# Examples\n\n```golang\npackage gween\n\nimport (\n  \"github.com/tanema/gween/ease\"\n  \"github.com/tanema/gween/gween\"\n)\n\n// increase the value from 0 to 5 in 10 seconds\nvar tweenLinear = gween.New(0, 5, 10, ease.Linear)\ncurrent, isFinished := tweenLinear.Update(dt)\n\n// make some text fall from the top of the screen, bouncing on y=300, in 4 seconds\nvar tweenLabel = gween.new(0, 300, 4, ease.OutBounce)\nlabel.Y, _ = tweenLabel.Update(dt)\n\n// fade background from white to black and foregrond from black to red in 2 seconds\ncurrentBGColor = [4]float32{255, 255, 255, 255}\ncurrentColor = [4]float32{0, 0, 0, 0}\nvar tweenBackground = gween.new(255, 0, 2, ease.Linear)\nvar tweenRed = gween.new(255, 0, 2, ease.Linear)\ncurrentBG, _ := tweenBackground.Update(dt)\ncurrentBGColor = [4]float32{currentBG, currentBG, currentBG, currentBG}\ncurrentColor[0], _ = tweenRed.Update(dt)\n\n// sequence increasing linearly from 0 to 4 over 10 seconds, \n// then decreasing outElastic 4 to 0 over 2 seconds\nvar sequence = gween.NewSequence(\n  gween.New(0, 4, 10, ease.Linear),\n  gween.New(4, 0, 2, ease.OutElastic),\n)\n// set to infinitely loop\nsequence.SetLoop(-1)\nval, tweenCompleted, seqenceCompleted = sequence.Update(dt)\n```\n\n# Interface\n\n## Tween\n\n### Creation\n\n```golang\nt := gween.New(begin, end, duration, easingFunction)\n```\n\nCreates a new tween.\n\n* `begin` is the start value\n* `end` is the ending value\n* `duration` means how much the change will take until it's finished. It must be a positive number.\n* `easingFunction` can be either a function or a function name (see the easing section below).\n\nThis function only creates and returns the tween. It must be captured in a variable\nand updated via `t.Update(dt)` in order for the changes to take place.\n\n### Methods\n\n```golang\ncurrentValue, isFinished := t.Update(dt)\n```\n\nGradually changes the `currentValue` toward the `end` value as time passes.\n\n* `t` is a tween returned by `gween.New`\n* `dt` is the difference in time. It will be added to the internal time counter of\n  the tween. The current value at the current value will be returned using selected\n  easing function.\n* `currentValue` is the current eased value for the current time.\n* `isFinised` is `true` if the tween has reached its limit (its *internal clock* is `\u003e= duration`). It is false otherwise.\n\nWhen the tween is complete, the `currentValue` will be equal to the `end` value.\nThe way they change over time will depend on the chosen easing function.\n\nIf `dt` is positive, the easing will be applied until the internal clock equals\n`duration`, at which point the easing will stop. If it is negative,\nthe easing will play \"backwards\", until it reaches the initial value.\n\n\n```golang\ncurrentValue, isFinished := t.Set(clock)\n```\n\nMoves a tween's internal clock to a particular moment.\n\n* `t` is a tween returned by `gween.New`\n* `clock` is a positive number or 0. It's the new value of the tween's internal clock.\n* `currentValue` is the value of the tween at the time set.\n* `isFinished` works like in `t.Update`; it's `true` if the tween has reached its\n  end, and `false` otherwise.\n\n\n## Sequence\n\n### Creation\n\n```golang\ns := gween.NewSeqence(tweens ...*Tween)\n```\n\nSequences can be used to execute tweens in sequence. They also provide looping\nand \"yoyo\" functionality.\n\n* `tweens` the tweens to be executed in sequential order\n\nThis function only creates and returns the sequence. It must be captured in a variable\nand updated via `s.Update(dt)` in order for the changes to take place.\n\n### Methods\n\n```golang\ncurrentValue, tweenCompleted, seqeuenceCompleted := s.Update(dt)\n```\n\nGradually changes the `currentValue` from the `begin` value to the `end` value \nof each tween in the sequence as time passes. If a `dt` is too large for the current\ntween, the \"overflow\" amount will automatically be carried into the next tween until the\nentire `dt` is exhausted by the tweens in the sequence, or the sequence completes.\n\n* `s` is a sequence returned by `gween.NewSequence`\n* `dt` is the difference in time. It will be added to the internal time counter of\n  the current tween and \"overflow\" to the next until completed exhausted.\n* `currentValue` is the current eased value for the current time.\n* `tweenCompleted` is `true` if any tween within the sequence has completed during this update.\n* `sequenceCompleted` is `true` if the entire sequence and all loops have completed. \n  * When configured to loop indefinitely, this will always be `false`\n\n```golang\ns.SetLoop(l)\n```\nDefaults to `1`\n\nConfigures the sequence to \"loop\" `l` times. When `l` is `-1`, sequence will\nloop infinitely.\n\nWhen used with `s.SetYoyo(true)`, a single \"loop\" starts and ends at the\n`begin`ning of the first tween; making its way out to the `end` of the final\ntween and back again.\n\n```golang\ns.SetYoyo(bool)\n```\nDefaults to `false`\n\nConfigures the sequence on whether to \"yoyo\" between the `begin`ning of the \nfirst tween and the `end` of the last tween.\n\n* When `yoyo` is `false`:\n  * A single loop of the sequence is when all tweens are completed in forward order.\n  * When the final loop of the sequence is complete, the `currentValue` will be \n  equal to the `end` value of the final tween.\n* When `yoyo` is `true`:\n  * A single loop is when all tweens have completed in forward order, and then completed again in reverse order.\n  * When the final loop of the sequence is complete, the `currentValue` will be \n  equal to the `begin` value of the first tween.\n\n```golang\ns.Reset()\n```\n\nResets all tweens in the sequence and sets the \"current\" tween back to the first. Also, \nsets the remaining loop count back to the initial value last set using the \n`.SetLoop()` function (or `1` if using the default).\n\n```golang\ns.SetReverse(bool)\n```\nDefaults to `false`\n\nConfigures the sequence to run in \"reverse\" or not.\n\n* When `yoyo` is `false`:\n  * If `reverse` is `false`, the sequence will run forward and will loop back to\n  the beginning if available\n  * If `reverse` is `true`, the sequence will run backward and will loop back to\n  the end if available\n* When `yoyo` is `true`:\n  * The sequence will run according to normal yoyo logic. If a sequence has gone\n  from the start to the end, and is coming back to the start (reverse is true) \n  and you set reverse to false, then the sequence will start heading towards the\n  end again. When it reaches the end it will simply yoyo as expected. The inverse\n  is also true, if the sequence is heading to the end and you reverse it before\n  the end, it'll simply head toward the start and if it reaches the start it will\n  consume a loop and, if possible, start again.\n\n\n```golang\ns.Add(tweens ...*Tween)\n```\n\nAdds the `tweens` provided, in order, at the end of the existing tween list\n\n```golang\ns.Remove(index)\n```\n\nRemoves the tween at the desired `index`. If you call `.Remove()` on an index \nout of bounds, nothing happens.\n\n\n# Easing functions\n\nEasing functions are functions that express how slow/fast the interpolation happens in tween.\n\nGween comes with 45 default easing functions already built-in (adapted from [Enrique García Cota's easing library](https://github.com/kikito/tween.lua)).\n\n![tween families](https://kikito.github.io/tween.lua/img/tween-families.png)\n\nThe easing functions can be found in the `ease` package.\n\nThey can be divided into several families:\n\n* `linear` is the simplest easing function, straight from one value to the other.\n* `quad`, `cubic`, `quart`, `quint`, `expo`, `sine` and `circle` are all \"smooth\" curves that will make transitions look natural.\n* The `back` family starts by moving the interpolation slightly \"backwards\" before moving it forward.\n* The `bounce` family simulates the motion of an object bouncing.\n* The `elastic` family simulates inertia in the easing, like an elastic gum.\n\nEach family (except `linear`) has 4 variants:\n* `In` starts slow, and accelerates at the end\n* `Out` starts fast, and decelerates at the end\n* `InOut` starts and ends slow, but it's fast in the middle\n* `OutIn` starts and ends fast, but it's slow in the middle\n\n| family      | in        | out        | inOut        | outIn        |\n|-------------|-----------|------------|--------------|--------------|\n| **Linear**  | Linear    | Linear     | Linear       | Linear       |\n| **Quad**    | InQuad    | OutQuad    | InOutQuad    | OutInQuad    |\n| **Cubic**   | InCubic   | OutCubic   | InOutCubic   | OutInCubic   |\n| **Quart**   | InQuart   | OutQuart   | InOutQuart   | OutInQuart   |\n| **Quint**   | InQuint   | OutQuint   | InOutQuint   | OutInQuint   |\n| **Expo**    | InExpo    | OutExpo    | InOutExpo    | OutInExpo    |\n| **Sine**    | InSine    | OutSine    | InOutSine    | OutInSine    |\n| **Circ**    | InCirc    | OutCirc    | InOutCirc    | OutInCirc    |\n| **Back**    | InBack    | OutBack    | InOutBack    | OutInBack    |\n| **Bounce**  | InBounce  | OutBounce  | InOutBounce  | OutInBounce  |\n| **Elastic** | InElastic | OutElastic | InOutElastic | OutInElastic |\n\n## Custom easing functions\n\nYou are not limited to gween's easing functions; if you pass a function parameter\nin the easing, it will be used.\n\nThe passed function will need to suite the TweenFunc interface: `func(t, b, c, d float32) float32`\n\n* `t` (time): starts in 0 and usually moves towards duration\n* `b` (begin): initial value of the of the property being eased.\n* `c` (change): ending value of the property - starting value of the property\n* `d` (duration): total duration of the tween\n\nAnd must return the new value after the interpolation occurs.\n\nHere's an example using a custom easing.\n\n```golang\nlabelTween := tween.new(0, 300, 4, func(t, b, c, d) float32 {\n  return c*t/d + b // linear ease\n})\n```\n\n# Credits\n\nThe easing functions have been translated from Enrique García Cota's project in\n\nhttps://github.com/kikito/tween.lua\n\nSee the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanema%2Fgween","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanema%2Fgween","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanema%2Fgween/lists"}