{"id":29483741,"url":"https://github.com/gpoon21/keycolor","last_synced_at":"2026-03-02T22:02:02.174Z","repository":{"id":294553090,"uuid":"987321964","full_name":"gpoon21/KeyColor","owner":"gpoon21","description":"Generates unique and consistent colors based on a specific key.","archived":false,"fork":false,"pushed_at":"2025-05-21T23:59:00.000Z","size":127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-21T22:39:21.711Z","etag":null,"topics":["color-contrast","color-generation","color-mapping","color-palette","data-visualization","net-library","net-standard","nuget-package","open-source"],"latest_commit_sha":null,"homepage":"","language":"C#","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/gpoon21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-05-20T23:00:40.000Z","updated_at":"2025-05-22T22:50:01.000Z","dependencies_parsed_at":"2025-05-21T01:25:55.509Z","dependency_job_id":"f1297c8f-94d9-4d49-9e5a-470d2468f420","html_url":"https://github.com/gpoon21/KeyColor","commit_stats":null,"previous_names":["gpoon21/keycolor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gpoon21/KeyColor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpoon21%2FKeyColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpoon21%2FKeyColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpoon21%2FKeyColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpoon21%2FKeyColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpoon21","download_url":"https://codeload.github.com/gpoon21/KeyColor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpoon21%2FKeyColor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265401329,"owners_count":23758989,"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":["color-contrast","color-generation","color-mapping","color-palette","data-visualization","net-library","net-standard","nuget-package","open-source"],"created_at":"2025-07-15T04:01:37.030Z","updated_at":"2026-03-02T22:02:02.108Z","avatar_url":"https://github.com/gpoon21.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KeyColor\n[![NuGet (with prereleases)](https://img.shields.io/nuget/vpre/KeyColor.svg?logo=nuget)](https://www.nuget.org/packages/KeyColor)\n\nKeyColor is a .NET library that generates unique and consistent colors based on input keys. It's perfect for applications that need deterministic color generation, such as data visualization, user interfaces, and color-coded elements.\n\nIf you find this project helpful, please consider giving it a star! ⭐\n\n## Features\n\n- **Deterministic Color Generation**: Same input always produces the same color\n- **Text Contrast Guarantee**: Default settings ensure text readability on generated colors\n- **Type Support**: Generate colors from strings, byte arrays, or structs\n- **Customizable Parameters**: Control saturation, lightness, and brightness ranges\n- **Framework Support**: \n  - .NET 9.0\n  - .NET 8.0\n  - .NET 7.0\n  - .NET Standard 2.0\n- **High Performance**: Optimized for both modern and legacy .NET frameworks\n- **Thread Safety**: Static `ColorFrom` APIs are thread-safe, `KeyColorGenerator` has thread-safe color generation\n\n## Demo\n\n\u003ca href=\"https://brave-bush-06f230610.6.azurestaticapps.net/\" target=\"_blank\"\u003e\n  \u003cimg src=\"ReadmeAsssets/Screenshot.png\" alt=\"KeyColor Demo Screenshot\"\u003e\n\u003c/a\u003e\n\nTry out the \u003ca href=\"https://brave-bush-06f230610.6.azurestaticapps.net/\" target=\"_blank\"\u003elive demo\u003c/a\u003e to see KeyColor in action!\n\n## Installation\n\nInstall KeyColor via NuGet:\n\n```bash\ndotnet add package KeyColor\n```\n\n## Quick Start\n\n```csharp\n// Using string as input\nvar color1 = ColorFrom.String(\"uniqueKey\");\nstring cssColor1 = color1.ToCssColor(); // Returns \"#RRGGBB\"\n\n// Using struct as input\nvar myStruct = new MyStruct();\nvar color2 = ColorFrom.Key(myStruct);\n\n// Using byte array as input\nbyte[] data = new byte[] { 1, 2, 3 };\nvar color3 = ColorFrom.Span(data);\n\n// Generate random color\nvar randomColor = ColorFrom.Rng();\n```\n\n## Advanced Usage\n\n### Customizing Color Generation\n\n```csharp\nvar generator = new KeyColorGenerator();\n\n// Customize saturation range (0-1)\ngenerator.Saturation.Min = 0.3;\ngenerator.Saturation.Max = 0.7;\n\n// Customize lightness range (0-1)\ngenerator.Lightness.Min = 0.2;\ngenerator.Lightness.Max = 0.8;\n\n// Customize brightness range (0-255)\ngenerator.Brightness.Min = 80;\ngenerator.Brightness.Max = 200;\n\n// Generate color with custom settings\nvar color = generator.GetUniqueColor(\"myKey\");\n```\n\n### Text Visibility\n\nThe default configuration ensures that both black and white text will be readable on any generated color:\n\n- **Lightness Range**: Constrained between 0.2 and 0.8 (not too dark, not too light)\n- **Brightness Range**: Kept between 80-200 (moderate brightness)\n- **Perceived Brightness**: Algorithm considers human eye perception of different colors\n\nThis means you can safely overlay text on generated colors without additional contrast checks for most use cases.\n\n## API Reference\n\n### ColorFrom (Static Class)\n\n- `String(string key)`: Generate color from string input\n- `Key\u003cT\u003e(T key) where T : struct`: Generate color from struct\n- `Span\u003cT\u003e(ReadOnlySpan\u003cT\u003e span) where T : struct`: Generate color from span\n- `Rng()`: Generate random color\n\nAll methods in `ColorFrom` are thread-safe and can be safely called from multiple threads.\n\n### KeyColorGenerator (Class)\n\n- `GetUniqueColor(string label)`: Generate color from string\n- `GetUniqueColor\u003cT\u003e(T key) where T : struct`: Generate color from struct\n- `GetUniqueColor(ReadOnlySpan\u003cbyte\u003e key)`: Generate color from byte span\n\n**Thread Safety Note**: The color generation methods are thread-safe, but modifying properties (Seed, Saturation, Lightness, Brightness) is not thread-safe. If you need to modify these properties, do it before making the generator available to multiple threads.\n\n### GeneratedColor (Struct)\n\n- `R`: Red component (0-255)\n- `G`: Green component (0-255)\n- `B`: Blue component (0-255)\n- `ToArray()`: Convert to byte array\n- `ToCssColor()`: Convert to CSS color string\n\n\n## Performance\n\nHere's a performance comparison of `ColorFrom.Key\u003cstruct\u003e` across different .NET versions:\n\n| Framework         | Mean      | Allocated |\n|-------------------|-----------|-----------|\n| .NET 9.0          | 680.5 ns  | 0 bytes   |\n| .NET 8.0          | 688.6 ns  | 0 bytes   |\n| .NET 7.0          | 689.0 ns  | 0 bytes   |\n| .NET Core 3.1     | 1,475 ns  | 1.2 KB    |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpoon21%2Fkeycolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpoon21%2Fkeycolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpoon21%2Fkeycolor/lists"}