mirror of
https://github.com/taigrr/colorhash.git
synced 2026-04-02 03:08:48 -07:00
* chore: update deps, fix escape codes, expand tests, add README - Bump Go 1.18 → 1.26, simplecolorpalettes v0.9.5 → v0.9.7 - Fix swapped fg/bg ANSI escape code values in trueColorString - Expand test suite from 2 to 13 tests (determinism, positivity, color assignment, background contrast, stringer palette) - Add README with usage examples * feat: add OKLCH-aware palette generation Add GenerateOKLCHPalette() which creates n evenly-spaced colors in the OKLCH color space at a given lightness and chroma. This produces perceptually uniform palettes where all colors appear equally bright. Uses the new OKLCH support from simplecolorpalettes. Note: go.mod contains a replace directive for local development that must be removed before merge (after simplecolorpalettes is published). * build: update simplecolorpalettes to v0.9.8 (charmtone palette)
22 lines
627 B
Go
22 lines
627 B
Go
package colorhash
|
|
|
|
import (
|
|
"github.com/taigrr/simplecolorpalettes/simplecolor"
|
|
)
|
|
|
|
// GenerateOKLCHPalette generates n evenly-spaced colors in the OKLCH color space
|
|
// at the given lightness and chroma. This produces a perceptually uniform palette
|
|
// where all colors appear equally bright and saturated.
|
|
func GenerateOKLCHPalette(n int, l, c float64) simplecolor.SimplePalette {
|
|
if n <= 0 {
|
|
return simplecolor.SimplePalette{}
|
|
}
|
|
palette := make(simplecolor.SimplePalette, n)
|
|
step := 360.0 / float64(n)
|
|
for i := 0; i < n; i++ {
|
|
h := float64(i) * step
|
|
palette[i] = simplecolor.FromOKLCH(l, c, h)
|
|
}
|
|
return palette
|
|
}
|