{"id":51124904,"url":"https://github.com/w0rm/elm-timestep","last_synced_at":"2026-06-25T06:30:59.445Z","repository":{"id":358286833,"uuid":"1240783768","full_name":"w0rm/elm-timestep","owner":"w0rm","description":"Decouple simulation rate from display refresh rate with a fixed timestep","archived":false,"fork":false,"pushed_at":"2026-05-16T15:42:30.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-28T19:39:48.099Z","etag":null,"topics":["animations","elm","simulation"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/w0rm/elm-timestep/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/w0rm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"w0rm"}},"created_at":"2026-05-16T15:08:05.000Z","updated_at":"2026-05-16T15:40:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/w0rm/elm-timestep","commit_stats":null,"previous_names":["w0rm/elm-timestep"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/w0rm/elm-timestep","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w0rm%2Felm-timestep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w0rm%2Felm-timestep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w0rm%2Felm-timestep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w0rm%2Felm-timestep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w0rm","download_url":"https://codeload.github.com/w0rm/elm-timestep/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w0rm%2Felm-timestep/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34763481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["animations","elm","simulation"],"created_at":"2026-06-25T06:30:58.904Z","updated_at":"2026-06-25T06:30:59.436Z","avatar_url":"https://github.com/w0rm.png","language":"Elm","funding_links":["https://github.com/sponsors/w0rm"],"categories":[],"sub_categories":[],"readme":"# elm-timestep\n\nAdvance a simulation in fixed-size steps, independent of display\nrefresh rate. Based on Glenn Fiedler's\n[Fix Your Timestep!](https://www.gafferongames.com/post/fix_your_timestep/).\n\n`Browser.Events.onAnimationFrameDelta` fires at the display rate —\n60 Hz, 120 Hz, irregular under load. Integrating motion by the raw\nΔt makes the simulation behave differently per machine. `advance`\nruns the step function as many times as the elapsed Δt covers and\nsaves the leftover, so the simulation runs at the rate you chose\nregardless of what the browser is doing.\n\n```elm\nimport Duration exposing (Duration)\nimport Length exposing (Length)\nimport Quantity\nimport Speed exposing (Speed)\nimport Timestep exposing (Timestep)\n\n\ntype alias Model =\n    { position : Length\n    , velocity : Speed\n    , timestep : Timestep\n    }\n\n\ninit : Model\ninit =\n    { position = Quantity.zero\n    , velocity = Speed.metersPerSecond 1\n    , timestep =\n        Timestep.init\n            { duration = Duration.seconds (1 / 60)\n            , maxSteps = 2\n            }\n    }\n\n\nupdate : Duration -\u003e Model -\u003e Model\nupdate dt model =\n    Timestep.advance step dt model\n\n\nstep : Model -\u003e Model\nstep model =\n    let\n        traveled =\n            model.velocity |\u003e Quantity.for (Timestep.duration model.timestep)\n    in\n    { model | position = model.position |\u003e Quantity.plus traveled }\n```\n\n## Spiral of death\n\nA slow frame produces a big Δt, which produces a big catch-up burst,\nwhich makes the next frame even slower. `maxSteps` caps how many\nsteps a single `advance` can run, so the catch-up can’t snowball.\nPast the cap, the simulation goes into slow motion instead.\n\n- `maxSteps = 1` — never catch up; hiccups cost simulated time.\n- `maxSteps = 2` — absorb one missed step. A good default.\n\n## Interpolation\n\nWhen the simulation rate doesn’t divide the display rate, steps fire\nunevenly and the scene stutters. To smooth it, keep the previous\nposition alongside the current one and blend by `Timestep.progress`\n(the fraction of a step accumulated, in `[0, 1)`):\n\n```elm\ntype alias Model =\n    { prevPosition : Length\n    , position : Length\n    , velocity : Speed\n    , timestep : Timestep\n    }\n\n\nstep : Model -\u003e Model\nstep model =\n    let\n        traveled =\n            model.velocity |\u003e Quantity.for (Timestep.duration model.timestep)\n    in\n    { model\n        | prevPosition = model.position\n        , position = model.position |\u003e Quantity.plus traveled\n    }\n\n\nrendered : Model -\u003e Length\nrendered model =\n    Quantity.interpolateFrom\n        model.prevPosition\n        model.position\n        (Timestep.progress model.timestep)\n```\n\nThis renders one step behind wall-clock — the trade for motion that’s\nsmooth at any display rate without ever extrapolating past a computed\nstate.\n\n## Examples\n\n- Bouncing ball ([source](https://github.com/w0rm/elm-timestep/tree/main/examples/src/BouncingBall.elm), [demo](https://unsoundscapes.com/elm-timestep/examples/bouncing-ball/)) — naïve variable-Δt vs fixed timestep, with a stall button.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw0rm%2Felm-timestep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw0rm%2Felm-timestep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw0rm%2Felm-timestep/lists"}