{"id":13561690,"url":"https://github.com/ianmackenzie/elm-1d-parameter","last_synced_at":"2025-03-15T03:28:26.068Z","repository":{"id":57675128,"uuid":"197092293","full_name":"ianmackenzie/elm-1d-parameter","owner":"ianmackenzie","description":"Generate evenly spaced interpolated values in Elm","archived":false,"fork":false,"pushed_at":"2019-07-18T00:52:41.000Z","size":15,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T20:13:08.024Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ianmackenzie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-16T00:37:14.000Z","updated_at":"2023-11-04T19:54:48.000Z","dependencies_parsed_at":"2022-09-02T15:02:00.728Z","dependency_job_id":null,"html_url":"https://github.com/ianmackenzie/elm-1d-parameter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-1d-parameter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-1d-parameter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-1d-parameter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianmackenzie%2Felm-1d-parameter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianmackenzie","download_url":"https://codeload.github.com/ianmackenzie/elm-1d-parameter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243680534,"owners_count":20330145,"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":[],"created_at":"2024-08-01T13:01:00.012Z","updated_at":"2025-03-15T03:28:26.049Z","avatar_url":"https://github.com/ianmackenzie.png","language":"Elm","funding_links":[],"categories":["Elm"],"sub_categories":[],"readme":"# elm-1d-parameter\n\n`elm-1d-parameter` is an [Elm](http://elm-lang.org) package to help with\ngenerating evenly spaced values such as (but not limited to) `Float`s,\n[`Color`][3]s, [`Quantity`][1]s, or [`Point2d`][2]s.\n\nThe core idea is that there are many functions that let you interpolate between\ntwo values based on a parameter value that ranges from 0 to 1; 0 gives you the\nfirst value, 1 gives you the second value, 0.5 gives you a value half way in\nbetween, etc. Some examples from [`elm-float-extra`][4], [`elm-color-extra`][7],\n[`elm-units`][5] and [`elm-geometry`][6] that work this way:\n\n```elm\nFloat.Extra.interpolateFrom :\n    Float -- first value\n    -\u003e Float -- second value\n    -\u003e Float -- interpolation parameter\n    -\u003e Float\n\nColor.Interpolate.interpolate :\n    Space -- what color space to interpolate in (e.g. HSL)\n    -\u003e Color -- first color\n    -\u003e Color -- second color\n    -\u003e Float -- interpolation parameter\n    -\u003e Color\n\nQuantity.interpolateFrom :\n    Quantity Float units\n    -\u003e Quantity Float units\n    -\u003e Float\n    -\u003e Quantity Float units\n\nPoint2d.interpolateFrom :\n    Point2d\n    -\u003e Point2d\n    -\u003e Float\n    -\u003e Point2d\n```\n\nNote that by partially applying the above functions, we can turn them all into\nthe form `Float -\u003e a`:\n\n```elm\n-- Float -\u003e Float\nFloat.Extra.interpolateFrom 5 10\n\n-- Float -\u003e Color\nColor.Interpolate.interpolate\n    Color.Interpolate.HSL\n    Color.red\n    Color.blue\n\n-- Float -\u003e Length\nQuantity.interpolateFrom (meters 10) (meters 20)\n\n-- Float -\u003e Point2d\nPoint2d.interpolateFrom startPoint endPoint\n```\n\nThe functions in this package all take a function of the form `Float -\u003e a`,\nevaluate it at a bunch of evenly-spaced parameter values between 0 and 1, and\nreturn the results as a `List a` or `Array a`:\n\n```elm\nParameter1d.steps 5 (Float.Extra.interpolateFrom 2 3)\n--\u003e [ 2, 2.2, 2.4, 2.6, 2.8, 3 ]\n```\n\nThe results do not themselves have to be `Float`s:\n\n```elm\nParameter1d.steps 10 \u003c|\n    Color.Interpolate.interpolate\n        Color.Interpolate.HSL\n        Color.red\n        Color.blue\n```\n\n![HSL-interpolated colors](https://ianmackenzie.github.io/elm-1d-parameter/1.0.0/README/ColorInterpolationHSL.png)\n\n```elm\nParameter1d.steps 10 \u003c|\n    Color.Interpolate.interpolate\n        Color.Interpolate.RGB\n        Color.red\n        Color.blue\n```\n\n![RGB-interpolated colors](https://ianmackenzie.github.io/elm-1d-parameter/1.0.0/README/ColorInterpolationRGB.png)\n\n```elm\nParameter1d.steps 20 \u003c|\n    Point2d.interpolateFrom\n        (Point2d.fromCoordinates ( 20, 20 ))\n        (Point2d.fromCoordinates ( 280, 130 ))\n```\n\n![Interpolated points](https://ianmackenzie.github.io/elm-1d-parameter/1.0.0/README/PointInterpolation.png)\n\nVarious different functions are provided that let you control what parameter\nvalues get used (and therefore what values get returned):\n\n```elm\nimport Float.Extra as Float\n\nParameter1d.steps 4 (Float.interpolateFrom 2 3)\n--\u003e [ 2, 2.25, 2.5, 2.75, 3 ]\n\nParameter1d.leading 4 (Float.interpolateFrom 2 3)\n--\u003e [ 2, 2.25, 2.5, 2.75 ]\n\nParameter1d.trailing 4 (Float.interpolateFrom 2 3)\n--\u003e [ 2.25, 2.5, 2.75, 3 ]\n\nParameter1d.inBetween 4 (Float.interpolateFrom 2 3)\n--\u003e [ 2.25, 2.5, 2.75 ]\n\nParameter1d.midpoints 4 (Float.interpolateFrom 2 3)\n--\u003e [ 2.125, 2.375, 2.625, 2.875 ]\n```\n\n\n\nNote that if you just want the actual parameter values, you can pass the\n`identity` function as the last argument:\n\n```elm\nParameter1d.steps 4 identity\n--\u003e [ 0, 0.25, 0.5, 0.75, 1 ]\n```\n\n## Why?\n\nInstead of using this package and writing\n\n```elm\nParameter1d.steps 1000 (Float.interpolateFrom 100 200)\n```\n\nyou could use `List.range` and `List.map` to get the same result:\n\n```elm\nList.range 0 1000\n    |\u003e List.map\n        (\\i -\u003e\n            let\n                parameterValue =\n                    toFloat i / 1000\n            in\n            Float.interpolateFrom 100 200 parameterValue\n        )\n```\n\nAlternatively, you could use [`List.Extra.initialize`][8]:\n\n```elm\nList.Extra.initialize 1001\n    (\\i -\u003e\n        let\n            parameterValue =\n                toFloat i / 1000\n        in\n        Float.interpolateFrom 100 200 parameterValue\n    )\n```\n\nOn my machine, using the built-in `List` functions is slowest on both Chrome and\nFirefox; `List.Extra.initialize` is fastest in Firefox but `Parameter1d.steps`\nis far, far faster in Chrome. Runs per second of the above code in both\nbrowsers (more is better):\n\n```\nMethod                | Chrome        | Firefox\n----------------------|---------------|--------------\nList.range/List.map   | 10,022        | 10,255\nList.Extra.initialize | 16,976 (1.7x) | 26,689 (2.6x)\nParameter1d.steps     | 87,213 (8.7x) | 17,628 (1.7x)\n```\n\nThe `Parameter1d.Array` functions are about the same in speed to calling\n`Array.initialize` yourself (perhaps even slightly slower), but are still a\nbit more convenient to use, for example\n\n```elm\nParameter1d.Array.steps 4 (Float.interpolateFrom 100 200)\n```\n\nvs.\n\n```elm\nArray.initialize 5\n    (\\i -\u003e Float.interpolateFrom 100 200 (toFloat i / 4))\n```\n\n[1]: https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/Quantity\n[2]: https://package.elm-lang.org/packages/ianmackenzie/elm-geometry/latest/Point2d\n[3]: https://package.elm-lang.org/packages/avh4/elm-color/latest/Color\n[4]: https://package.elm-lang.org/packages/ianmackenzie/elm-float-extra/latest/Float-Extra#interpolateFrom\n[5]: https://package.elm-lang.org/packages/ianmackenzie/elm-units/latest/Quantity#interpolateFrom\n[6]: https://package.elm-lang.org/packages/ianmackenzie/elm-geometry/latest/Point2d#interpolateFrom\n[7]: https://package.elm-lang.org/packages/noahzgordon/elm-color-extra/latest/Color-Interpolate#interpolate\n[8]: https://package.elm-lang.org/packages/elm-community/list-extra/latest/List-Extra#initialize\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmackenzie%2Felm-1d-parameter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianmackenzie%2Felm-1d-parameter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianmackenzie%2Felm-1d-parameter/lists"}