{"id":19989915,"url":"https://github.com/teacat/noire","last_synced_at":"2025-10-13T14:32:32.755Z","repository":{"id":55140732,"uuid":"165886129","full_name":"teacat/noire","owner":"teacat","description":"🎨 Light/darken, mix, (de)saturate the colors in Golang with CMYK / RGB / HSV / HSL / Hex / HTML supported.","archived":false,"fork":false,"pushed_at":"2021-01-07T16:11:45.000Z","size":324,"stargazers_count":54,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-22T11:17:48.703Z","etag":null,"topics":["color","go","golang","hex"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/teacat/noire","language":"Go","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/teacat.png","metadata":{"files":{"readme":"README-tw.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":"2019-01-15T16:35:18.000Z","updated_at":"2025-08-20T03:28:24.000Z","dependencies_parsed_at":"2022-08-14T13:10:59.463Z","dependency_job_id":null,"html_url":"https://github.com/teacat/noire","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/teacat/noire","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fnoire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fnoire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fnoire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fnoire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teacat","download_url":"https://codeload.github.com/teacat/noire/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fnoire/sbom","scorecard":{"id":871305,"data":{"date":"2025-08-11","repo":{"name":"github.com/teacat/noire","commit":"bf22cdfc4f284267f77bf395beafe52126648f00"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T04:18:15.772Z","repository_id":55140732,"created_at":"2025-08-24T04:18:15.772Z","updated_at":"2025-08-24T04:18:15.772Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015739,"owners_count":26085748,"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-10-13T02:00:06.723Z","response_time":61,"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","go","golang","hex"],"created_at":"2024-11-13T04:50:47.265Z","updated_at":"2025-10-13T14:32:32.737Z","avatar_url":"https://github.com/teacat.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Noire [![GoDoc](https://godoc.org/github.com/teacat/noire?status.svg)](https://godoc.org/github.com/teacat/noire) [![Coverage Status](https://coveralls.io/repos/github/teacat/noire/badge.svg?branch=master#1)](https://coveralls.io/github/teacat/noire?branch=master) [![Build Status](https://travis-ci.org/teacat/noire.svg?branch=master#1)](https://travis-ci.org/teacat/noire) [![Go Report Card](https://goreportcard.com/badge/github.com/teacat/noire#1)](https://goreportcard.com/report/github.com/teacat/noire)\n\n支援 RGB、HSL、HSV、CMYK、Hex、HTML 顏色代碼進行轉換與顏色（亮度、飽和度…等）編輯的套件。\n\n這個套件需要至少 **Go 1.10**，因為會使用到 [`math.Round`](https://golang.org/pkg/math/#Round) 四捨五入函式。\n\n## 色彩演算法\n\nNoire 能夠將下列顏色互相轉換。\n\n-   RGB\n-   CMYK\n-   HSL\n-   HSV\n-   Hex\n-   HTML\n\n## 效能比較\n\n```\n測試規格：\n4.2 GHz Intel Core i7 (8750H)\n32 GB 2666 MHz DDR4\n\ngoos: windows\ngoarch: amd64\npkg: github.com/teacat/noire\nBenchmarkCMYKToRGB-12         \t100000000\t        22.5 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGBToCMYK-12         \t50000000\t        26.9 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGBToHSL-12          \t50000000\t        26.6 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSLToRGB-12          \t100000000\t        17.2 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSVToRGB-12          \t100000000\t        15.3 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGBToHSV-12          \t50000000\t        29.3 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGBToHex-12          \t20000000\t        85.4 ns/op\t      32 B/op\t       4 allocs/op\nBenchmarkHexToRGB-12          \t50000000\t        36.1 ns/op\t       8 B/op\t       1 allocs/op\nBenchmarkHTMLToRGBName-12     \t20000000\t       118 ns/op\t      40 B/op\t       3 allocs/op\nBenchmarkHTMLToRGBHex-12      \t30000000\t        41.0 ns/op\t       8 B/op\t       1 allocs/op\nBenchmarkRGBToHTML-12         \t20000000\t       103 ns/op\t      32 B/op\t       4 allocs/op\nBenchmarkMix-12               \t 5000000\t       292 ns/op\t     112 B/op\t       5 allocs/op\nBenchmarkHue-12               \t50000000\t        33.5 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkSaturation-12        \t50000000\t        33.7 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkLightness-12         \t50000000\t        33.7 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkAdjustHue-12         \t20000000\t        79.0 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkLighten-12           \t20000000\t        78.2 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkDarken-12            \t20000000\t        77.8 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkSaturate-12          \t20000000\t        74.1 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkDesaturate-12        \t20000000\t        79.0 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkGrayscale-12         \t20000000\t        71.8 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkComplement-12        \t20000000\t        79.9 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkTint-12              \t30000000\t        40.8 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkShade-12             \t30000000\t        40.9 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkInvert-12            \t50000000\t        24.9 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkLuminanaceWCAG-12    \t10000000\t       224 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkLuminanace-12        \t300000000\t         6.00 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkContrast-12          \t 5000000\t       257 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkIsLight-12           \t2000000000\t         0.26 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkIsDark-12            \t2000000000\t         0.26 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSV-12               \t50000000\t        34.2 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSVA-12              \t50000000\t        35.0 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSL-12               \t50000000\t        31.9 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHSLA-12              \t50000000\t        32.0 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGB-12               \t2000000000\t         0.52 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkRGBA-12              \t2000000000\t         0.26 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCMYK-12              \t50000000\t        32.9 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHex-12               \t20000000\t        90.1 ns/op\t      32 B/op\t       4 allocs/op\nBenchmarkHTMLHex-12           \t10000000\t       146 ns/op\t      40 B/op\t       5 allocs/op\nBenchmarkHTMLName-12          \t20000000\t       107 ns/op\t      32 B/op\t       4 allocs/op\nBenchmarkHTMLRGBA-12          \t 2000000\t       839 ns/op\t      96 B/op\t       5 allocs/op\nPASS\nok  \tgithub.com/teacat/noire\t67.640s\nSuccess: Benchmarks passed.\n```\n\n## 安裝方式\n\n打開終端機並且透過 `go get` 安裝此套件即可。\n\n```bash\n$ go get github.com/teacat/noire\n```\n\n## 使用方式\n\n透過 `noire.NewRGB`（或是 `NewHex` 等）來初始化一個顏色，並且透過 `Lighten` 或 `Tint` 等函式開始編輯該色彩。\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/teacat/noire\"\n)\n\nfunc main() {\n\tc := noire.NewRGB(255, 255, 255)\n\tfmt.Println(c.Invert().Hex())       // 輸出：000000\n\tfmt.Println(c.Invert().HTML())      // 輸出：Black\n\tfmt.Println(c.Lighten(1).RGB())     // 輸出：255, 255, 255\n}\n```\n\n## 函式說明\n\n這裡有些函式無法透過圖表說明他們的用途，但這些你都能夠在超讚的 [GoDoc](https://godoc.org/github.com/teacat/noire) 裡面看到如何使用他們。\n\n-   `Hue`：取得基於 HSL 演算法的色相角度值。\n-   `Saturation`：會取得基於 HSL 演算法的飽和百分比。\n-   `Lightness`：取得基於 HSL 演算法的明亮百分比。\n-   `LuminanaceWCAG`：取得目前顏色基於 WCAG 2.0 演算法的流明度。\n-   `Luminanace`：取得目前顏色的流明度。\n-   `Contrast`：透過 WCAG 流明度演算法算出與指定顏色的對比度。\n-   `IsLight`：得知顏色是否為亮色，但有些時候這可能與肉眼所見的不相符。\n-   `IsDark`：得知顏色是否為暗色，但有些時候這可能與肉眼所見的不相符。\n\n### 加亮（Lighten）\n\n![顏色示意圖](./assets/lighten.png)\n\n以 HSL 的模式提高顏色的亮度，但這有可能會過於明亮。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Lighten(0.15).Hex())   // 輸出：EAADC2\n}\n```\n\n### 明亮（Brighten）\n\n![顏色示意圖](./assets/brighten.png)\n\n以 RGB 的模式提高顏色的亮度。\n\n```go\nfunc main() {\n\tc := NewRGB(0, 0, 0)\n\tfmt.Println(c.Brighten(0.1).Hex())   // 輸出：1A1A1A\n}\n```\n\n### 混和加亮（Tint）\n\n![顏色示意圖](./assets/tint.png)\n\n將目前顏色混上白色以達到最佳平衡與飽和來提高顏色亮度。\n\n```go\nfunc main() {\n\tc := NewRGB(0, 0, 0)\n\tfmt.Println(c.Tint(0.1).Hex())   // 輸出：1A1A1A\n}\n```\n\n### 調暗（Darken）\n\n![顏色示意圖](./assets/darken.png)\n\n以 HSL 的模式降低顏色的亮度，但這有可能會過於暗沉。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Darken(0.15).Hex())   // 輸出：CB3366\n}\n```\n\n### 混和調暗（Shade）\n\n![顏色示意圖](./assets/shade.png)\n\n將目前顏色混上黑色以達到最佳平衡與飽和來降低顏色亮度。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Shade(0.15).Hex())   // 輸出：BA5F7E\n}\n```\n\n### 提高飽和度（Saturate）\n\n![顏色示意圖](./assets/saturate.png)\n\n以 HSL 的模式提高顏色的飽和度。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Saturate(0.5).Hex())   // 輸出：FF4C88\n}\n```\n\n### 降低飽和度（Desaturate）\n\n![顏色示意圖](./assets/desaturate.png)\n\n以 HSL 的模式降低顏色的飽和度。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Desaturate(0.15).Hex())   // 輸出：AE9DA3\n}\n```\n\n### 更改色相角度（AdjustHue）\n\n![顏色示意圖](./assets/adjust-hue.png)\n\n以 HSL 的模式旋轉色相角度，當超過 360 度時會繼續以順時針旋轉。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.AdjustHue(30).Hex())   // 輸出：DB8270\n}\n```\n\n### 混合（Mix）\n\n![顏色示意圖](./assets/mix.png)\n\n將顏色與另一個顏色混合，並且自訂第二顏色的混色權重。\n\n```go\nfunc main() {\n\tc1 := NewHex(\"F00\")\n\tc2 := NewHex(\"00F\")\n\tfmt.Println(c1.Mix(c2, 0.5).HTML())   // 輸出：Purple\n}\n```\n\n### 反相色（Invert）\n\n![顏色示意圖](./assets/invert.png)\n\n取得 RGB 顏色在絕對座標上的相反位置，並將整個顏色反轉（不是互補色但趨近於）。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Invert().Hex())   // 輸出：248F6B\n}\n```\n\n### 互補色（Complement）\n\n![顏色示意圖](./assets/complement.png)\n\n取得顏色的互補色（色相環的對面色），相當於 `AdjustHue(180)`。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Complement().Hex())   // 輸出：70DBB7\n}\n```\n\n### 灰階（Grayscale）\n\n![顏色示意圖](./assets/grayscale.png)\n\n將顏色轉換成灰階色調，相當於 `Desaturate(1)`。\n\n```go\nfunc main() {\n\tc := NewRGB(219, 112, 148)\n\tfmt.Println(c.Grayscale().Hex())   // 輸出：A5A5A5\n}\n```\n\n### 前景色（Foreground）\n\n![顏色示意圖](./assets/foreground.png)\n\n取得基於目前顏色流明度而推薦的前景文字顏色（黑或白），越暗的背景就會採用白色文字，反之亦然。\n\n```go\nfunc main() {\n\tc := NewHTML(\"Green\")\n\tfmt.Println(c.Foreground().HTML())   // 輸出：White\n\tc = NewHTML(\"Red\")\n\tfmt.Println(c.Foreground().HTML())   // 輸出：White\n\tc = NewHTML(\"Yellow\")\n\tfmt.Println(c.Foreground().HTML())   // 輸出：Black\n}\n```\n\n## 可參考文件\n\n[RGB 轉 HSV, HSL (線上色碼轉換 HSL, HSV, RGB, HEX)](https://www.ginifab.com.tw/tools/colors/rgb_to_hsv_hsl.html)\n\n[ozdemirburak/iris: PHP library for color manipulation and conversion.](https://github.com/ozdemirburak/iris)\n\n[G17: Ensuring that a contrast ratio of at least 7:1 exists between text (and images of text) and background behind the text | Techniques for WCAG 2.0](https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests)\n\n[Using Sass to automatically pick text colors](https://medium.com/dev-channel/using-sass-to-automatically-pick-text-colors-4ba7645d2796)\n\n[Relative luminance - Wikipedia](https://en.wikipedia.org/wiki/Relative_luminance)\n\n[user interface - Given a background color, how to get a foreground color that makes it readable on that background color? - Stack Overflow](https://stackoverflow.com/questions/3116260/given-a-background-color-how-to-get-a-foreground-color-that-makes-it-readable-o)\n\n[image - Formula to determine brightness of RGB color - Stack Overflow](https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color)\n\n[Ant Design 色板生成算法演进之路 - 知乎](https://zhuanlan.zhihu.com/p/32422584)\n\n[Sass 基础——颜色函数\\_Preprocessor, Sass, SCSS 教程\\_w3cplus](https://www.w3cplus.com/preprocessor/sass-color-function.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteacat%2Fnoire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteacat%2Fnoire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteacat%2Fnoire/lists"}