Documentation ¶
Overview ¶
The colorful package provides all kinds of functions for working with colors.
Index ¶
- Constants
- func ANSIWriter(writer io.Writer) io.Writer
- func AlmostEqualRGB(c1, c2 RGB) bool
- func DistanceCIE76(c1, c2 RGB) float64
- func DistanceCIE94(c1, c2 RGB) float64
- func DistanceCIEDE2000(c1, c2 RGB) float64
- func DistanceCIEDE2000klch(c1, c2 RGB, kl, kc, kh float64) float64
- func DistanceLab(c1, c2 RGB) float64
- func DistanceLuv(c1, c2 RGB) float64
- func DistanceRGB(c1, c2 RGB) float64
- func ExpandToInt32(r *RGB) (int32, int32, int32)
- func FromLab(t float64) float64
- func HCLToLab(h, c, l float64) (L, a, b float64)
- func HCLWhiteRef(c RGB, wref [3]float64) (h, co, l float64)
- func Hex(c Color) int32
- func IsRGB(c Color) bool
- func LabToHCL(L, a, b float64) (h, c, l float64)
- func LabToXYZ(l, a, b float64) (x, y, z float64)
- func LabToXYZWhiteRef(l, a, b float64, wref [3]float64) (x, y, z float64)
- func LabWhiteRef(c RGB, wref [3]float64) (l, a, b float64)
- func Light(c Color) float64
- func LinearRGBToXYZ(r, g, b float64) (x, y, z float64)
- func LuvToXYZ(l, u, v float64) (x, y, z float64)
- func LuvToXYZWhiteRef(l, u, v float64, wref [3]float64) (x, y, z float64)
- func Name(c Color) string
- func RGB255(c RGB) (r, g, b uint8)
- func ToFastLinearRGB(c RGB) (r, g, b float64)
- func ToHCL(c RGB) (h, co, l float64)
- func ToHSL(c RGB) (h, s, l float64)
- func ToHSV(c RGB) (h, s, v float64)
- func ToLab(c RGB) (l, a, b float64)
- func ToLinearRGB(c RGB) (r, g, b float64)
- func ToLuv(c RGB) (l, u, v float64)
- func ToLuvWhiteRef(c RGB, wref [3]float64) (l, u, v float64)
- func ToRGB(c Color) (int, int, int)
- func ToXYY(c RGB) (x, y, Y float64)
- func ToXYYWhiteRef(c RGB, wref [3]float64) (x, y, Y float64)
- func ToXYZ(c RGB) (x, y, z float64)
- func TranslateANSI(text string) string
- func Valid(c Color) bool
- func XYYToXYZ(x, y, Y float64) (X, Yout, Z float64)
- func XYZToLab(x, y, z float64) (l, a, b float64)
- func XYZToLabWhiteRef(x, y, z float64, wref [3]float64) (l, a, b float64)
- func XYZToLinearRGB(x, y, z float64) (r, g, b float64)
- func XYZToLuv(x, y, z float64) (l, a, b float64)
- func XYZToLuvWhiteRef(x, y, z float64, wref [3]float64) (l, u, v float64)
- func XYZToXYY(X, Y, Z float64) (x, y, Yout float64)
- func XYZToXYYWhiteRef(X, Y, Z float64, wref [3]float64) (x, y, Yout float64)
- type Color
- type RGB
- func FromXYY(x, y, Y float64) RGB
- func FromXYZ(x, y, z float64) RGB
- func GenLabWhiteRef(l, a, b float64, wref [3]float64) RGB
- func Lab(l, a, b float64) RGB
- func NewRGB(col color.Color) (RGB, bool)
- func NewRGBBlendLuv(c1, c2 RGB, t float64) RGB
- func NewRGBFromBlendHCL(col1, col2 RGB, t float64) RGB
- func NewRGBFromBlendHSV(c1, c2 RGB, t float64) RGB
- func NewRGBFromBlendLab(c1, c2 RGB, t float64) RGB
- func NewRGBFromBlendRGB(c1, c2 RGB, t float64) RGB
- func NewRGBFromClamped(c RGB) RGB
- func NewRGBFromFastLinearRGB(r, g, b float64) RGB
- func NewRGBFromHCL(h, c, l float64) RGB
- func NewRGBFromHCLWhite(h, c, l float64, wref [3]float64) RGB
- func NewRGBFromHSL(h, s, l float64) RGB
- func NewRGBFromHSV(H, S, V float64) RGB
- func NewRGBFromHex(color string) (RGB, error)
- func NewRGBFromLinearRGB(r, g, b float64) RGB
- func NewRGBFromLuv(l, u, v float64) RGB
- func NewRGBFromLuvWhiteRef(l, u, v float64, wref [3]float64) RGB
Constants ¶
const ( Black = valid + iota Maroon Green Olive Purple Teal Silver Gray Red Lime Yellow Blue Fuchsia Aqua White Noname16 Noname17 Noname18 Noname19 Noname20 Noname21 Noname22 Noname23 Noname24 Noname25 Noname26 Noname27 Noname28 Noname29 Noname30 Noname31 Noname32 Noname33 Noname34 Noname35 Noname36 Noname37 Noname38 Noname39 Noname40 Noname41 Noname42 Noname43 Noname44 Noname45 Noname46 Noname47 Noname48 Noname49 Noname50 Noname51 Noname52 Noname53 Noname54 Noname55 Noname56 Noname57 Noname58 Noname59 Noname60 Noname61 Noname62 Noname63 Noname64 Noname65 Noname66 Noname67 Noname68 Noname69 Noname70 Noname71 Noname72 Noname73 Noname74 Noname75 Noname76 Noname77 Noname78 Noname79 Noname80 Noname81 Noname82 Noname83 Noname84 Noname85 Noname86 Noname87 Noname88 Noname89 Noname90 Noname91 Noname92 Noname93 Noname94 Noname95 Noname96 Noname97 Noname98 Noname99 Noname100 Noname101 Noname102 Noname103 Noname104 Noname105 Noname106 Noname107 Noname108 Noname109 Noname110 Noname111 Noname112 Noname113 Noname114 Noname115 Noname116 Noname117 Noname118 Noname119 Noname120 Noname121 Noname122 Noname123 Noname124 Noname125 Noname126 Noname127 Noname128 Noname129 Noname130 Noname131 Noname132 Noname133 Noname134 Noname135 Noname136 Noname137 Noname138 Noname139 Noname140 Noname141 Noname142 Noname143 Noname144 Noname145 Noname146 Noname147 Noname148 Noname149 Noname150 Noname151 Noname152 Noname153 Noname154 Noname155 Noname156 Noname157 Noname158 Noname159 Noname160 Noname161 Noname162 Noname163 Noname164 Noname165 Noname166 Noname167 Noname168 Noname169 Noname170 Noname171 Noname172 Noname173 Noname174 Noname175 Noname176 Noname177 Noname178 Noname179 Noname180 Noname181 Noname182 Noname183 Noname184 Noname185 Noname186 Noname187 Noname188 Noname189 Noname190 Noname191 Noname192 Noname193 Noname194 Noname195 Noname196 Noname197 Noname198 Noname199 Noname200 Noname201 Noname202 Noname203 Noname204 Noname205 Noname206 Noname207 Noname208 Noname209 Noname210 Noname211 Noname212 Noname213 Noname214 Noname215 Noname216 Noname217 Noname218 Noname219 Noname220 Noname221 Noname222 Noname223 Noname224 Noname225 Noname226 Noname227 Noname228 Noname229 Noname230 Noname231 Noname232 Noname233 Noname234 Noname235 Noname236 Noname237 Noname238 Noname239 Noname240 Noname241 Noname242 Noname243 Noname244 Noname245 Noname246 Noname247 Noname248 Noname249 Noname250 Noname251 Noname252 Noname253 Noname254 Noname255 AliceBlue AntiqueWhite AquaMarine Azure Beige Bisque BlanchedAlmond BlueViolet Brown BurlyWood CadetBlue Chartreuse Chocolate Coral CornflowerBlue CornSilk Crimson DarkBlue DarkCyan DarkGoldenrod DarkGray DarkGreen DarkKhaki DarkMagenta DarkOliveGreen DarkOrange DarkOrchid DarkRed DarkSalmon DarkSeaGreen DarkSlateBlue DarkSlateGray DarkTurquoise DarkViolet DeepPink DeepSkyBlue DimGray DodgerBlue FireBrick FloralWhite ForestGreen GainsBoro GhostWhite Gold Goldenrod GreenYellow Honeydew HotPink IndianRed Indigo Ivory Khaki Lavender LavenderBlush LawnGreen LemonChiffon LightBlue LightCoral LightCyan LightGoldenrodYellow LightGray LightGreen LightPink LightSalmon LightSeaGreen LightSkyBlue LightSlateGray LightSteelBlue LightYellow LimeGreen Linen MediumAquamarine MediumBlue MediumOrchid MediumPurple MediumSeaGreen MediumSlateBlue MediumSpringGreen MediumTurquoise MediumVioletRed MidnightBlue MintCream MistyRose Moccasin OldLace OliveDrab Orange OrangeRed Orchid PaleGoldenrod PaleGreen PaleTurquoise PaleVioletRed PapayaWhip PeachPuff Peru Pink Plum PowderBlue RebeccaPurple RosyBrown RoyalBlue SaddleBrown Salmon SandyBrown SeaGreen Seashell Sienna SkyBlue SlateBlue SlateGray Snow SpringGreen SteelBlue Tan Thistle Tomato Turquoise Violet Wheat WhiteSmoke YellowGreen )
Note that the order of these options is important -- it follows the definitions used by ECMA and XTerm. Hence any further named colors must begin at a value not less than 256.
const Delta = 1.0 / 255.0
This is the tolerance used when comparing colors using AlmostEqualRGB.
const ( // Reset is used to indicate that the color should use the vanilla terminal colors. (Basically go back to the defaults.) Reset = Special | iota )
Special colors.
const (
ValidConst = valid
)
Variables ¶
This section is empty.
Functions ¶
func ANSIWriter ¶
ANSIWriter returns an io.Writer which translates any ANSI escape codes written to it into color tags. Other escape codes don't have an effect and are simply removed. The translated text is written to the provided writer.
func AlmostEqualRGB ¶
Check for equality between colors within the tolerance Delta (1/255).
func DistanceCIE76 ¶
That's actually the same, but I don't want to break code.
func DistanceCIE94 ¶
Uses the CIE94 formula to calculate color distance. More accurate than DistanceLab, but also more work.
func DistanceCIEDE2000 ¶
DistanceCIEDE2000 uses the Delta E 2000 formula to calculate color distance. It is more expensive but more accurate than both DistanceLab and DistanceCIE94.
func DistanceCIEDE2000klch ¶
DistanceCIEDE2000klch uses the Delta E 2000 formula with custom values for the weighting factors kL, kC, and kH.
func DistanceLab ¶
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.
func DistanceLuv ¶
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.
func DistanceRGB ¶
DistanceRGB computes the distance between two colors in RGB space. This is not a good measure! Rather do it in Lab space.
func HCLWhiteRef ¶
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]
func Hex ¶
NewRGBFromHex returns the color's hexadecimal RGB 24-bit value with each component consisting of a single byte, ala R << 16 | G << 8 | B. If the color is unknown or unset, -1 is returned.
func LabToXYZWhiteRef ¶
func LabWhiteRef ¶
Converts the given color to CIE L*a*b* space, taking into account a given reference white. (i.e. the monitor's white)
func LinearRGBToXYZ ¶
func LuvToXYZWhiteRef ¶
func ToFastLinearRGB ¶
NewRGBFromFastLinearRGB is much faster than and almost as accurate as NewRGBFromLinearRGB. they only produce good results for valid colors r,g,b in [0,1].
func ToHCL ¶
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
func ToHSL ¶
NewRGBFromHSL returns the Hue [0..360], Saturation [0..1], and Luminance (lightness) [0..1] of the color.
func ToLinearRGB ¶
NewRGBFromLinearRGB converts the color into the linear RGB space (see http://www.sjbrown.co.uk/2004/05/14/gamma-correct-rendering/).
func ToLuv ¶
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]
func ToLuvWhiteRef ¶
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]
func ToRGB ¶
ToRGB returns the red, green, and blue components of the color, with each component represented as a value 0-255. In the event that the color cannot be broken up (not set usually), -1 is returned for each value.
func ToXYY ¶
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]
func ToXYYWhiteRef ¶
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]
func TranslateANSI ¶
TranslateANSI replaces ANSI escape sequences found in the provided string with color tags and returns the resulting string.
func XYZToLabWhiteRef ¶
func XYZToLinearRGB ¶
XYZToLinearRGB converts from CIE XYZ-space to Linear RGB space.
func XYZToLuvWhiteRef ¶
func XYZToXYY ¶
Well, the name is bad, since it's xyY but Golang needs me to start with a capital letter to make the method public.
func XYZToXYYWhiteRef ¶
Types ¶
type Color ¶
type Color uint64
Color represents a color. The low numeric values are the same as used by ECMA-48, and beyond that XTerm. A 24-bit RGB value may be used by adding in the IsRGB flag. For Color names we use the W3C approved color names.
We use a 64-bit integer to allow future expansion if we want to add an 8-bit alpha, while still leaving us some room for extra options.
Note that on various terminals colors may be approximated however, or not supported at all. If no suitable representation for a color is known, the library will simply not set any color, deferring to whatever default attributes the terminal uses.
func FindColor ¶
FindColor attempts to find a given color, or the best match possible for it, from the palette given. This is an expensive operation, so results should be cached by the caller.
func NewColor ¶
NewColor creates a Color from a color name (W3C name). A hex value may be supplied as a string in the format "#ffffff".
func NewHexColor ¶
NewHexColor returns a color using the given 24-bit RGB value.
func NewRGBAColor ¶
NewRGBAColor makes a color from imageColor ("image/color")
func NewRGBColor ¶
NewRGBColor returns a new color with the given red, green, and blue values. Each value must be represented in the range 0-255.
func PaletteColor ¶
PaletteColor creates a color based on the palette index.
type RGB ¶
A color is stored internally using sRGB (standard RGB) values in the range 0-1
func GenLabWhiteRef ¶
Generates a color by using data given in CIE L*a*b* space, taking into account a given reference white. (i.e. the monitor's white)
func Lab ¶
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.
func NewRGBBlendLuv ¶
NewRGBBlendLuv 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
func NewRGBFromBlendHCL ¶
NewRGBFromBlendHCL 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
func NewRGBFromBlendHSV ¶
Use for NewRGBFromBlendLab, NewRGBBlendLuv or NewRGBFromBlendHCL.
func NewRGBFromBlendLab ¶
NewRGBFromBlendLab 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
func NewRGBFromBlendRGB ¶
Use NewRGBFromBlendLab, NewRGBBlendLuv or NewRGBFromBlendHCL.
func NewRGBFromClamped ¶
Returns Clamps the color into valid range, clamping each value to [0..1] If the color is valid already, this is a no-op.
func NewRGBFromFastLinearRGB ¶
NewRGBFromFastLinearRGB is much faster than and almost as accurate as NewRGBFromLinearRGB. BUT it is important to NOTE that they only produce good results for valid inputs r,g,b in [0,1].
func NewRGBFromHCL ¶
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 `l`, `a`, and `b` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
func NewRGBFromHCLWhite ¶
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]
func NewRGBFromHSL ¶
NewRGBFromHSL creates a new RGB given a Hue in [0..360], a Saturation [0..1], and a Luminance (lightness) in [0..1]
func NewRGBFromHSV ¶
NewRGBFromHSV creates a new RGB given a Hue in [0..360], a Saturation and a Value in [0..1]
func NewRGBFromHex ¶
NewRGBFromHex parses a "html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form.
func NewRGBFromLinearRGB ¶
NewRGBFromLinearRGB creates an sRGB color out of the given linear RGB color (see http://www.sjbrown.co.uk/2004/05/14/gamma-correct-rendering/).
func NewRGBFromLuv ¶
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`, `a`, and `b` values do not have corresponding
valid RGB values, check the FAQ in the README if you're unsure.
func NewRGBFromLuvWhiteRef ¶
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]