Package-Level Type Names (total 10, in which 4 are exported)
/* sort exporteds by: | */
A color is stored internally using sRGB (standard RGB) values in the range 0-1Bfloat64Gfloat64Rfloat64( Color) A98Rgb() (r, g, b float64) Check for equality between colors within the tolerance Delta (1/255). BlendA98Rgb blends two colors in the A98 RGB color-space.
t == 0 results in c1, t == 1 results in c2 BlendDisplayP3 blends two colors in the Display P3 color-space.
t == 0 results in c1, t == 1 results in c2 BlendHcl blends two colors in the CIE-L*C*h° color-space, which should result in a smoother blend.
t == 0 results in c1, t == 1 results in c2 You don't really want to use this, do you? Go for BlendLab, BlendLuv or BlendHcl. BlendLab blends two colors in the L*a*b* color-space, which should result in a smoother blend.
t == 0 results in c1, t == 1 results in c2 BlendLinearRgb blends two colors in the Linear RGB color-space.
Unlike BlendRgb, this will not produce dark color around the center.
t == 0 results in c1, t == 1 results in c2 BlendLuv blends two colors in the CIE-L*u*v* color-space, which should result in a smoother blend.
t == 0 results in c1, t == 1 results in c2 BlendLuvLCh blends two colors in the cylindrical CIELUV color space.
t == 0 results in c1, t == 1 results in c2 BlendOkLab blends two colors in the OkLab color-space, which should result in a better blend (even compared to BlendLab). BlendOkLch blends two colors in the OkLch color-space, which should result in a better blend (even compared to BlendHcl). BlendProPhotoRgb blends two colors in the ProPhoto RGB color-space.
t == 0 results in c1, t == 1 results in c2 BlendRec2020 blends two colors in the Rec. 2020 color-space.
t == 0 results in c1, t == 1 results in c2 You don't really want to use this, do you? Go for BlendLab, BlendLuv or BlendHcl. Returns Clamps the color into valid range, clamping each value to [0..1]
If the color is valid already, this is a no-op.( Color) DisplayP3() (r, g, b float64) DistanceCIE76 is the same as DistanceLab. Uses the CIE94 formula to calculate color distance. More accurate than
DistanceLab, but also more work. DistanceCIEDE2000 uses the Delta E 2000 formula to calculate color
distance. It is more expensive but more accurate than both DistanceLab
and DistanceCIE94. DistanceCIEDE2000klch uses the Delta E 2000 formula with custom values
for the weighting factors kL, kC, and kH. DistanceHPLuv calculates Euclidean distance in the HPLuv colorspace. No idea
how useful this is.
The Hue value is divided by 100 before the calculation, so that H, S, and L
have the same relative ranges. DistanceHSLuv calculates Euclidean distance in the HSLuv colorspace. No idea
how useful this is.
The Hue value is divided by 100 before the calculation, so that H, S, and L
have the same relative ranges. DistanceLab is a good measure of visual similarity between two colors!
A result of 0 would mean identical colors, while a result of 1 or higher
means the colors differ a lot. DistanceLinearRGB is deprecated in favour of DistanceLinearRgb.
They do the exact same thing. DistanceLinearRgb computes the distance between two colors in linear RGB
space. This is not useful for measuring how humans perceive color, but
might be useful for other things, like dithering. DistanceLuv is a good measure of visual similarity between two colors!
A result of 0 would mean identical colors, while a result of 1 or higher
means the colors differ a lot. DistanceRgb computes the distance between two colors in RGB space.
This is not a good measure! Rather do it in Lab space. DistanceRiemersma is a color distance algorithm developed by Thiadmer Riemersma.
It uses RGB coordinates, but he claims it has similar results to CIELUV.
This makes it both fast and accurate.
Sources:
https://www.compuphase.com/cmetric.htm
https://github.com/lucasb-eyer/go-colorful/issues/52 FastLinearRgb is much faster than and almost as accurate as LinearRgb.
BUT it is important to NOTE that they only produce good results for valid colors r,g,b in [0,1]. HPLuv returns the Hue, Saturation and Luminance of the color in the HSLuv
color space. Hue in [0..360], a Saturation [0..1], and a Luminance
(lightness) in [0..1].
Note that HPLuv can only represent pastel colors, and so the Saturation
value could be much larger than 1 for colors it can't represent. HSLuv returns the Hue, Saturation and Luminance of the color in the HSLuv
color space. Hue in [0..360], a Saturation [0..1], and a Luminance
(lightness) in [0..1]. Converts the given color to HCL space using D65 as reference white.
H values are in [0..360], C and L values are in [0..1] although C can overshoot 1.0 Converts the given color to HCL space, taking into account
a given reference white. (i.e. the monitor's white)
H values are in [0..360], C and L values are in [0..1] Hex returns the hex "html" representation of the color, as in #ff0080. Hsl returns the Hue [0..359], Saturation [0..1], and Luminance (lightness) [0..1] of the color. Hsv returns the Hue [0..359], Saturation and Value [0..1] of the color. Checks whether the color exists in RGB space, i.e. all values are in [0..1] Converts the given color to CIE L*a*b* space using D65 as reference white. Converts the given color to CIE L*a*b* space, taking into account
a given reference white. (i.e. the monitor's white) LinearRgb converts the color into the linear RGB space (see http://www.sjbrown.co.uk/2004/05/14/gamma-correct-rendering/). Converts the given color to CIE L*u*v* space using D65 as reference white.
L* is in [0..1] and both u* and v* are in about [-1..1] Converts the given color to LuvLCh space using D65 as reference white.
h values are in [0..360], C and L values are in [0..1] although C can overshoot 1.0 Converts the given color to LuvLCh space, taking into account
a given reference white. (i.e. the monitor's white)
h values are in [0..360], c and l values are in [0..1] Converts the given color to CIE L*u*v* space, taking into account
a given reference white. (i.e. the monitor's white)
L* is in [0..1] and both u* and v* are in about [-1..1]( Color) OkLab() (l, a, b float64)( Color) OkLch() (l, c, h float64)( Color) ProPhotoRgb() (r, g, b float64) Might come in handy sometimes to reduce boilerplate code. Implement the Go color.Color interface.( Color) Rec2020() (r, g, b float64) Converts the given color to CIE xyY space using D65 as reference white.
(Note that the reference white is only used for black input.)
x, y and Y are in [0..1] Converts the given color to CIE xyY space, taking into account
a given reference white. (i.e. the monitor's white)
(Note that the reference white is only used for black input.)
x, y and Y are in [0..1]( Color) Xyz() (x, y, z float64)( Color) XyzD50() (x, y, z float64) Used to simplify HSLuv testing.
Color : github.com/charmbracelet/x/ansi.Color
Color : database/sql/driver.Validator
Color : image/color.Color
func A98Rgb(r, g, b float64) Color
func DisplayP3(r, g, b float64) Color
func FastHappyColor() Color
func FastHappyColorWithRand(rand RandInterface) Color
func FastHappyPalette(colorsCount int) (colors []Color)
func FastHappyPaletteWithRand(colorsCount int, rand RandInterface) (colors []Color)
func FastLinearRgb(r, g, b float64) Color
func FastWarmColor() Color
func FastWarmColorWithRand(rand RandInterface) Color
func FastWarmPalette(colorsCount int) (colors []Color)
func FastWarmPaletteWithRand(colorsCount int, rand RandInterface) (colors []Color)
func HappyColor() (c Color)
func HappyColorWithRand(rand RandInterface) (c Color)
func HappyPalette(colorsCount int) ([]Color, error)
func HappyPaletteWithRand(colorsCount int, rand RandInterface) ([]Color, error)
func Hcl(h, c, l float64) Color
func HclWhiteRef(h, c, l float64, wref [3]float64) Color
func Hex(scol string) (Color, error)
func HPLuv(h, s, l float64) Color
func Hsl(h, s, l float64) Color
func HSLuv(h, s, l float64) Color
func Hsv(H, S, V float64) Color
func Lab(l, a, b float64) Color
func LabWhiteRef(l, a, b float64, wref [3]float64) Color
func LinearRgb(r, g, b float64) Color
func Luv(l, u, v float64) Color
func LuvLCh(l, c, h float64) Color
func LuvLChWhiteRef(l, c, h float64, wref [3]float64) Color
func LuvWhiteRef(l, u, v float64, wref [3]float64) Color
func MakeColor(col color.Color) (Color, bool)
func OkLab(l, a, b float64) Color
func OkLch(l, c, h float64) Color
func ProPhotoRgb(r, g, b float64) Color
func Rec2020(r, g, b float64) Color
func SoftPalette(colorsCount int) ([]Color, error)
func SoftPaletteEx(colorsCount int, settings SoftPaletteSettings) ([]Color, error)
func SoftPaletteExWithRand(colorsCount int, settings SoftPaletteSettings, rand RandInterface) ([]Color, error)
func SoftPaletteWithRand(colorsCount int, rand RandInterface) ([]Color, error)
func Sorted(cs []Color) []Color
func WarmColor() (c Color)
func WarmColorWithRand(rand RandInterface) (c Color)
func WarmPalette(colorsCount int) ([]Color, error)
func WarmPaletteWithRand(colorsCount int, rand RandInterface) ([]Color, error)
func Xyy(x, y, Y float64) Color
func Xyz(x, y, z float64) Color
func XyzD50(x, y, z float64) Color
func Color.BlendA98Rgb(c2 Color, t float64) Color
func Color.BlendDisplayP3(c2 Color, t float64) Color
func Color.BlendHcl(col2 Color, t float64) Color
func Color.BlendHsv(c2 Color, t float64) Color
func Color.BlendLab(c2 Color, t float64) Color
func Color.BlendLinearRgb(c2 Color, t float64) Color
func Color.BlendLuv(c2 Color, t float64) Color
func Color.BlendLuvLCh(col2 Color, t float64) Color
func Color.BlendOkLab(c2 Color, t float64) Color
func Color.BlendOkLch(col2 Color, t float64) Color
func Color.BlendProPhotoRgb(c2 Color, t float64) Color
func Color.BlendRec2020(c2 Color, t float64) Color
func Color.BlendRgb(c2 Color, t float64) Color
func Color.Clamped() Color
func labs2cols(labs []lab_t) (cols []Color)
func parseHexColor(r, g, b string, bits int, factor float64) (Color, error)
func randomPimpWithRand(rand RandInterface) Color
func randomWarmWithRand(rand RandInterface) Color
func github.com/charmbracelet/x/ansi.HexColor.color() *Color
func Sorted(cs []Color) []Color
func Color.AlmostEqualRgb(c2 Color) bool
func Color.BlendA98Rgb(c2 Color, t float64) Color
func Color.BlendDisplayP3(c2 Color, t float64) Color
func Color.BlendHcl(col2 Color, t float64) Color
func Color.BlendHsv(c2 Color, t float64) Color
func Color.BlendLab(c2 Color, t float64) Color
func Color.BlendLinearRgb(c2 Color, t float64) Color
func Color.BlendLuv(c2 Color, t float64) Color
func Color.BlendLuvLCh(col2 Color, t float64) Color
func Color.BlendOkLab(c2 Color, t float64) Color
func Color.BlendOkLch(col2 Color, t float64) Color
func Color.BlendProPhotoRgb(c2 Color, t float64) Color
func Color.BlendRec2020(c2 Color, t float64) Color
func Color.BlendRgb(c2 Color, t float64) Color
func Color.DistanceCIE76(c2 Color) float64
func Color.DistanceCIE94(cr Color) float64
func Color.DistanceCIEDE2000(cr Color) float64
func Color.DistanceCIEDE2000klch(cr Color, kl, kc, kh float64) float64
func Color.DistanceHPLuv(c2 Color) float64
func Color.DistanceHSLuv(c2 Color) float64
func Color.DistanceLab(c2 Color) float64
func Color.DistanceLinearRGB(c2 Color) float64
func Color.DistanceLinearRgb(c2 Color) float64
func Color.DistanceLuv(c2 Color) float64
func Color.DistanceRgb(c2 Color) float64
func Color.DistanceRiemersma(c2 Color) float64
func allToAllDistancesCIEDE2000(cs []Color) edgeDistance
A HexColor is a Color stored as a hex string "#rrggbb". It implements the
database/sql.Scanner, database/sql/driver.Value,
encoding/json.Unmarshaler and encoding/json.Marshaler interfaces.Bfloat64Gfloat64Rfloat64 Decode - deserialize function for https://github.com/kelseyhightower/envconfig( HexColor) MarshalJSON() ([]byte, error)( HexColor) MarshalYAML() (interface{}, error)(*HexColor) Scan(value interface{}) error( HexColor) String() string(*HexColor) UnmarshalJSON(data []byte) error(*HexColor) UnmarshalYAML(unmarshal func(interface{}) error) error(*HexColor) Value() (driver.Value, error)
*HexColor : database/sql.Scanner
*HexColor : database/sql/driver.Valuer
HexColor : encoding/json/v2.Marshaler
*HexColor : encoding/json/v2.Unmarshaler
HexColor : expvar.Var
HexColor : fmt.Stringer
HexColor : context.stringer
HexColor : os/signal.stringer
HexColor : runtime.stringer
A function which can be used to restrict the allowed color-space. The higher, the better quality but the slower. Usually two figures. Use up to 160000 or 8000 samples of the L*a*b* space (and thus calls to CheckColor).
Set this to true only if your CheckColor shapes the Lab space weirdly.
func SoftPaletteEx(colorsCount int, settings SoftPaletteSettings) ([]Color, error)
func SoftPaletteExWithRand(colorsCount int, settings SoftPaletteSettings, rand RandInterface) ([]Color, error)
An edgeDistance is a map from an edge (pair of indices) to a distance
between the two vertices.
func allToAllDistancesCIEDE2000(cs []Color) edgeDistance
func sortEdges(m edgeDistance) []edgeIdxs
An edgeIdxs describes an edge in a graph or tree. The vertices in the edge
are indexes into a list of Color values.
func minSpanTree(nc int, es []edgeIdxs) map[edgeIdxs]struct{}
func sortEdges(m edgeDistance) []edgeIdxs
func minSpanTree(nc int, es []edgeIdxs) map[edgeIdxs]struct{}
func traverseMST(mst map[edgeIdxs]struct{}, root int) []int
An element represents a single element of a set. It is used to
implement a disjoint-set forest. // Parent element // Rank (approximate depth) of the subtree with this element as root find returns an arbitrary element of a set when invoked on any element of
the set, The important feature is that it returns the same value when
invoked on any element of the set. Consequently, it can be used to test if
two elements belong to the same set.
func newElement() *element
func union(e1, e2 *element)
The algorithm works in L*a*b* color space and converts to RGB in the end.
L* in [0..1], a* and b* in [-1..1]Afloat64Bfloat64Lfloat64
func in(haystack []lab_t, upto int, needle lab_t) bool
func in(haystack []lab_t, upto int, needle lab_t) bool
func lab_dist(lab1, lab2 lab_t) float64
func lab_eq(lab1, lab2 lab_t) bool
func labs2cols(labs []lab_t) (cols []Color)
Package-Level Functions (total 124, in which 87 are exported)
Uses the HSV color space to generate colors with similar S,V but distributed
evenly along their Hue. This is fast but not always pretty.
If you've got time to spare, use Lab (the non-fast below).
FastLinearRgb is much faster than and almost as accurate as LinearRgb.
BUT it is important to NOTE that they only produce good results for valid inputs r,g,b in [0,1].
Uses the HSV color space to generate colors with similar S,V but distributed
evenly along their Hue. This is fast but not always pretty.
If you've got time to spare, use Lab (the non-fast below).
Creates a random bright, "pimpy" color through restricted HCL space.
This is slower than FastHappyColor but will likely give you colors which
have the same "brightness" if you run it many times.
Generates a color by using data given in HCL space using D65 as reference white.
H values are in [0..360], C and L values are in [0..1]
WARNING: many combinations of `h`, `c`, and `l` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
Generates a color by using data given in HCL space, taking
into account a given reference white. (i.e. the monitor's white)
H values are in [0..360], C and L values are in [0..1]
Hex parses a "html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form.
HPLuv creates a new Color from values in the HPLuv color space.
Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
The returned color values are clamped (using .Clamped), so this will never output
an invalid color.
Hsl creates a new Color given a Hue in [0..359], a Saturation [0..1], and a Luminance (lightness) in [0..1]
HSLuv creates a new Color from values in the HSLuv color space.
Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1].
The returned color values are clamped (using .Clamped), so this will never output
an invalid color.
Hsv creates a new Color given a Hue in [0..359], a Saturation and a Value in [0..1]
Generates a color by using data given in CIE L*a*b* space using D65 as reference white.
WARNING: many combinations of `l`, `a`, and `b` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
Generates a color by using data given in CIE L*u*v* space using D65 as reference white.
L* is in [0..1] and both u* and v* are in about [-1..1]
WARNING: many combinations of `l`, `u`, and `v` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
Generates a color by using data given in LuvLCh space using D65 as reference white.
h values are in [0..360], C and L values are in [0..1]
WARNING: many combinations of `l`, `c`, and `h` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
Generates a color by using data given in LuvLCh space, taking
into account a given reference white. (i.e. the monitor's white)
h values are in [0..360], C and L values are in [0..1]
Generates a color by using data given in CIE L*u*v* space, taking
into account a given reference white. (i.e. the monitor's white)
L* is in [0..1] and both u* and v* are in about [-1..1]
Constructs a colorful.Color from something implementing color.Color
Yeah, windows-stype Foo, FooEx, screw you golang...
Uses K-means to cluster the color-space and return the means of the clusters
as a new palette of distinctive colors. Falls back to K-medoid if the mean
happens to fall outside of the color-space, which can only happen if you
specify a CheckColor function.
A wrapper which uses common parameters.
Sorted sorts a list of Color values. Sorting is not a well-defined operation
for colors so the intention here primarily is to order colors so that the
transition from one to the next is fairly smooth.
Creates a random dark, "warm" color through restricted HCL space.
This is slower than FastWarmColor but will likely give you colors which have
the same "warmness" if you run it many times.
allToAllDistancesCIEDE2000 computes the CIEDE2000 distance between each pair of
colors. It returns a map from a pair of indices (u, v) with u < v to a
distance.
A much faster and still quite precise linearization using a 6th-order Taylor approximation.
See the accompanying Jupyter notebook for derivation of the constants.
minSpanTree computes a minimum spanning tree from a vertex count and a
distance-sorted edge list. It returns the subset of edges that belong to
the tree, including both (u, v) and (v, u) for each edge.
newElement creates a singleton set and returns its sole element.
traverseMST walks a minimum spanning tree in prefix order.
union establishes the union of two sets when given an element from each set.
Afterwards, the original sets no longer exist as separate entities.
For this part, we do as R's graphics.hcl does, not as wikipedia does.
Or is it the same?
Package-Level Variables (total 4, in which 2 are exported)
And another one.
This is the default reference white point.
HSLuv uses a rounded version of the D65. This has no impact on the final RGB
values, but to keep high levels of accuracy for internal operations and when
comparing to the test values, this modified white reference is used internally.
See this GitHub thread for details on these values:
https://github.com/hsluv/hsluv/issues/79