{"id":40942384,"url":"https://github.com/freder/piecewise","last_synced_at":"2026-01-22T04:36:35.360Z","repository":{"id":54223008,"uuid":"82294410","full_name":"freder/piecewise","owner":"freder","description":"a library for creating composable easing and envelope functions.","archived":false,"fork":false,"pushed_at":"2021-03-02T17:30:25.000Z","size":226,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-06-12T02:50:16.742Z","etag":null,"topics":["crossfade","easing","envelope","javascript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freder.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}},"created_at":"2017-02-17T12:16:08.000Z","updated_at":"2021-03-02T17:29:30.000Z","dependencies_parsed_at":"2022-08-13T09:31:06.771Z","dependency_job_id":null,"html_url":"https://github.com/freder/piecewise","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/freder/piecewise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freder%2Fpiecewise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freder%2Fpiecewise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freder%2Fpiecewise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freder%2Fpiecewise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freder","download_url":"https://codeload.github.com/freder/piecewise/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freder%2Fpiecewise/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28654815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"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":["crossfade","easing","envelope","javascript"],"created_at":"2026-01-22T04:36:35.294Z","updated_at":"2026-01-22T04:36:35.348Z","avatar_url":"https://github.com/freder.png","language":"JavaScript","readme":"# @freder/piecewise\n\na library for creating composable easing and envelope functions.\n\n\n## installation\n\n```\n# yarn\nyarn add @freder/piecewise\n\n# npm\nnpm install --save @freder/piecewise\n```\n\n\n## example: `easing` function\n\n```javascript\nconst piecewise = require('@freder/piecewise');\n\nfunction identity(t) {\n\treturn t;\n}\n\nfunction always(c) {\n\treturn (t) =\u003e c;\n}\n\nconst piecewiseEasingFn = piecewise.easing([\n\t{\n\t\ttInterval: [0, 0.5],\n\t\ttMap: [0, 1], // optional\n\t\teasingFn: identity,\n\t},\n\t{\n\t\ttInterval: [0.5, 0.8],\n\t\teasingFn: always(1),\n\t},\n\t{\n\t\ttInterval: [0.8, 1],\n\t\ttMap: [1, 0], // reverse\n\t\teasingFn: identity,\n\t},\n]);\n```\n\n`tInterval` is mapped to `tMap`, with which `easingFn` is called. `easingFn` only takes one argument `t`.\n\nvisualization:\u003cbr\u003e\n![](./images/easing.png)\n\n\n## example: `envelope` function\n\n```javascript\nconst piecewiseEnvelopeFn = piecewise.easing([\n\t{\n\t\ttInterval: [0, 0.5],\n\t\ttMap: [0, 1],\n\t\teasingFn: identity,\n\t},\n\t{\n\t\ttInterval: [0.5, 1],\n\t\ttMap: [1, 0],\n\t\teasingFn: identity,\n\t},\n]);\n\nconst finalFn = piecewise.envelope(piecewiseEnvelopeFn, piecewiseEasingFn);\n```\n\n`envelope` returns the product of the values of an envelope function and an easing function at time `t`.\n\nvisualization:\u003cbr\u003e\n![](./images/envelope.png)\u003cbr\u003e\ngrey: easing function\u003cbr\u003e\nred: envelope function\u003cbr\u003e\nblack: resulting function\n\n\n## example: `mix` function\n\n```javascript\nconst f1 = identity;\nconst f2 = always(1);\nconst finalFn = piecewise.mix(f1, f2, 0.7);\n```\n\n`mix` returns a new function that calculates the weighted mean of two functions at time `t`.\n\nvisualization:\u003cbr\u003e\n![](./images/mix.png)\u003cbr\u003e\ngrey: f1, f2\u003cbr\u003e\nblack: resulting function\n\n\n## example: `crossfade` function\n\n```javascript\nconst easingFn = piecewise.easing([\n\t{\n\t\ttInterval: [0, 0.6],\n\t\ttMap: [0, 1],\n\t\teasingFn: always(0),\n\t},\n\t{\n\t\ttInterval: [0.6, 0.8],\n\t\ttMap: [0, 1],\n\t\teasingFn: identity,\n\t},\n\t{\n\t\ttInterval: [0.8, 1],\n\t\ttMap: [0, 1],\n\t\teasingFn: always(1),\n\t},\n]);\n\nconst f1 = always(0.75);\nconst f2 = always(0.25);\nconst finalFn = piecewise.crossfade(easingFn, f1, f2);\n```\n\n`crossfade` mixes two functions and is controlled by `easingFn`.\n\nvisualization:\u003cbr\u003e\n![](./images/crossfade.png)\u003cbr\u003e\ngrey: f1, f2\u003cbr\u003e\nred: easing function\u003cbr\u003e\nblack: resulting function\n\n\n## visualization\n\n→ [visualization-example.js](./visualization-example.js)\n\n\n## utility functions\n\n```javascript\nconst easing = require('easing-js');\nconst { utils } = require('@freder/piecewise');\n\n// wrap penner easing function to only be a function of `t`:\nconst wrappedEasingFn = utils.wrapPennerFunction(easing.linear);\nwrappedEasingFn(0.7); // → 0.7\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreder%2Fpiecewise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreder%2Fpiecewise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreder%2Fpiecewise/lists"}