{"id":16166132,"url":"https://github.com/andorlando/color","last_synced_at":"2025-09-14T14:54:23.233Z","repository":{"id":65404467,"uuid":"397618343","full_name":"andOrlando/color","owner":"andOrlando","description":"Clean and efficient api for color conversion in lua","archived":false,"fork":false,"pushed_at":"2023-11-26T10:55:50.000Z","size":953,"stargazers_count":35,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T20:06:33.193Z","etag":null,"topics":["color","colors","hex","hsl","lua","rgb"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/andOrlando.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":"2021-08-18T13:52:50.000Z","updated_at":"2025-03-27T01:04:13.000Z","dependencies_parsed_at":"2024-10-14T01:06:25.226Z","dependency_job_id":"acdf73b0-f256-4400-a00b-6fefab7c622d","html_url":"https://github.com/andOrlando/color","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andOrlando/color","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andOrlando%2Fcolor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andOrlando%2Fcolor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andOrlando%2Fcolor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andOrlando%2Fcolor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andOrlando","download_url":"https://codeload.github.com/andOrlando/color/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andOrlando%2Fcolor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275121371,"owners_count":25409028,"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","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"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":["color","colors","hex","hsl","lua","rgb"],"created_at":"2024-10-10T02:53:24.965Z","updated_at":"2025-09-14T14:54:23.205Z","avatar_url":"https://github.com/andOrlando.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# color\nContains a bunch of useful function for conversion as well as well as a very nice api for just colors in general.\n\nIt can probably be easiest explained with a code snippet:\n```lua\ncolor = require 'color'\ndark_green = color.color { r=10, g=30, b=10 }\n\ndark_green.h, dark_green.s, dark_green.l\n-- Returns 120.0 0.5 0.07843137254902\n\ndark_green.h = 60\ndark_green.r, dark_green.g, dark_green.b\n-- Returns 30.0 30.0 10.0\n\nnewcolor = dark_green + \"60h\"\nnewcolor.h, newcolor.s, newcolor.l\n-- Returns 120.0 0.5 0.07843137254902\n-- creates a new color with the desired change (+60 hue)\n\ndark_green.h, dark_green.s, dark_green.l\n-- Returns 60.0 0.5 0.07843137254902\n-- doesn't modify the old color\n```\nAs you can see, when you update one variable all the rest update with it. This is done in a relatively intelligent \nmanner, however. Should you, in the example of the code snippet, update h, s or l again, it won't try to update the \nother values. Only when you access non-hsl entries will it update them. Once it's updated, you can access anything \nwithout it updating further until you change something again.\n\n# What's the point though?\nyou can do cool stuff like this!\n\n![Spinny Volume Thing](./images/spinny.gif)\n\nI do this by keeping track of two colors, one for the background and one for\nthe foreground. Whenever I go forwards a color, I increment the hue by 40 for\nboth, and whenever I go backwards I do the opposite. The two colors are exactly\n40 hues away. Then, to actually change the color of the arcchart I just use the\nhex parameter. The actual animation/easing is done with my\nother overengineered ricing project, [rubato](https://github.com/andOrlando/rubato). \nWhile you can only see the colors if your volume is at like 36,000% (the grey\nis 1-100%, the color changing one is 101-200%), it was a little annoying to have\nit not be smooth should I ever want to blow out my speakers.\n\n# Useful functions and more info\nFurthermore, it comes with a couple nice functions too:\n- `color.utils.hex_to_rgb`: takes in a string hex value (no # as of now) and returns rgb values from 0-255\n- `color.utils.rgb_to_hex`: takes in a table with entries r, g and b (or just as the first three entires) and returns a string hex value (with no #)\n- `color.utils.rgb_to_hsl`: takes in a table with entries r, g and b (or just as the first three entires) and returns a table with h, s and l\n- `color.utils.hsl_to_rgb`: takes in a table with entries h, s and l (or just as the first three entires) and returns a table with r, g and b\n- `color.transition`: takes two color objects and a method (constants defined in transition) and returns a function that transitions between the two colors. 0 would be color 1, 1 would be color 2, everything else is a color in between. For best results you probably want to use the HSL mode,\n\nA couple more notes about the color class:\n- r, g and b must be values between 0 and 255\n- s and l must be between 0 and 1, whereas h must be between 0 and 360\n- a must be between 0 and 1\n- by setting `disable_hsl=true` on initialization, you can prevent to hex \u003c-\u003e rgb conversions\n- by default it outputs it with a hashtag. If you don't want it to do this, set `hashtag=false` on initialization.\n- as shown in the example, you can just add values to it to create new colors that don't change the original color object\n\nAll the math was taken from [here](https://www.niwa.nu/2013/05/math-behind-colorspace-conversions-rgb-hsl/). \nI basically just put it into lua in a nice way. Me actaully kinda learning how to make this nice api comes\nfrom [here](https://ebens.me/post/implementing-proper-gettersetters-in-lua). Please pardon my godawful codestyle,\nI just do what I think looks pleasent, which I suppose is fitting for a ricer.\n\n# TODO\n- [ ] cool name?? (I do have color on luarocks, which is a pretty good name, but idk)\n- [X] Add better # support for hex\n- [ ] Add better checks (asserts and stuff)\n- [X] Add alpha and toggles for whether or not to include it\n- [ ] Do better setting of default methods (`obj._props.r = args.r or 0` kinda thing)\n- [X] Make do good readme\n- [X] Have smarter input reading (as in, don't require a table with r, g and b, look at first three indices\n- [ ] Allow for 0-1 rgb\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandorlando%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandorlando%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandorlando%2Fcolor/lists"}