Documentation
¶
Overview ¶
Package color provides methods for working with colors
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contrast ¶
Contrast calculates contrast ratio of foreground and background colors
Example ¶
c := Contrast(NewHex(0x222222), NewHex(0x40abf7)) fmt.Printf("ratio: %.2f:1\n", c)
Output: ratio: 6.35:1
func HUE2RGB ¶
HUE2RGB calculates HUE value for given RGB color
Example ¶
hue := HUE2RGB(0.3, 0.12, 0.56) fmt.Printf("Hue: %.4f\n", hue)
Output: Hue: 0.1848
Types ¶
type CMYK ¶
type CMYK struct { C float64 // Cyan M float64 // Magenta Y float64 // Yellow K float64 // Key (black) }
func RGB2CMYK ¶
RGB2CMYK converts RGB color to CMYK
Example ¶
fmt.Printf("%s\n", RGB2CMYK(RGB{127, 25, 75}))
Output: CMYK{C:0% M:80% Y:41% K:50%}
type HSL ¶
func RGB2HSL ¶
RGB2HSL converts RGB color to HSL
Example ¶
fmt.Printf("%s\n", RGB2HSL(RGB{127, 25, 75}))
Output: HSL{H:331° S:67% L:30% A:0%}
type HSV ¶
type HSV struct { H float64 // Hue S float64 // Saturation V float64 // Lightness A float64 // Alpha }
func RGB2HSV ¶
RGB2HSV converts RGB color to HSV (HSB)
Example ¶
fmt.Printf("%s\n", RGB2HSV(RGB{127, 25, 75}))
Output: HSV{H:331° S:80% V:50% A:0%}
type Hex ¶
type Hex struct {
// contains filtered or unexported fields
}
func Parse ¶
Parse parses color
Example ¶
fmt.Println(Parse("#ff6347")) fmt.Println(Parse("#B8F")) fmt.Println(Parse("#FF3B21A6")) fmt.Println(Parse("mintcream"))
Output: Hex{#FF6347} <nil> Hex{#BB88FF} <nil> Hex{#FF3B21A6} <nil> Hex{#F5FFFA} <nil>
func RGB2Hex ¶
RGB2Hex converts RGB color to Hex
Example ¶
fmt.Printf("%s\n", RGB2Hex(RGB{127, 25, 75}).ToWeb(true, false))
Output: #7F194B
func RGBA2Hex ¶
RGBA2Hex converts RGBA color to Hex
Example ¶
c := RGBA2Hex(RGBA{127, 25, 75, 204}) fmt.Printf("%s\n", c.ToWeb(true, false))
Output: #7F194BCC
func (Hex) IsRGBA ¶
IsRGBA returns true if color contains info about alpha channel
Example ¶
c1 := NewHex(0x7F194B) c2 := NewHex(0x7F194B5F) fmt.Printf("%s → %t\n", c1.ToWeb(true, false), c1.IsRGBA()) fmt.Printf("%s → %t\n", c2.ToWeb(true, false), c2.IsRGBA())
Output: #7F194B → false #7F194B5F → true
func (Hex) ToRGB ¶
ToRGB converts hex color to RGB
Example ¶
fmt.Printf("%s\n", NewHex(0x7F194B).ToRGB())
Output: RGB{R:127 G:25 B:75}
func (Hex) ToRGBA ¶
ToRGB converts hex color to RGBA
Example ¶
fmt.Printf("%s\n", NewHex(0x7F194B5F).ToRGBA())
Output: RGBA{R:127 G:25 B:75 A:0.37}
type RGB ¶
func CMYK2RGB ¶
CMYK2RGB converts CMYK color to RGB
Example ¶
fmt.Printf("%s\n", CMYK2RGB(CMYK{0, 0.8, 0.41, 0.5}))
Output: RGB{R:127 G:25 B:75}
func HSL2RGB ¶
HSL2RGB converts HSL color to RGB
Example ¶
c := HSL2RGB(HSL{H: 331.0 / 360.0, S: 67.0 / 100.0, L: 30.0 / 100.0}) fmt.Printf("%s\n", c)
Output: RGB{R:127 G:25 B:74}
func HSV2RGB ¶
HSV2RGB converts HSV (HSB) color to RGB
Example ¶
c := HSV2RGB(HSV{H: 331.0 / 360.0, S: 80.0 / 100.0, V: 50.0 / 100.0}) fmt.Printf("%s\n", c)
Output: RGB{R:127 G:25 B:74}
func Hex2RGB ¶
Hex2RGB converts Hex color to RGB
Example ¶
fmt.Printf("%s\n", Hex2RGB(NewHex(0x7F194B)))
Output: RGB{R:127 G:25 B:75}
func Term2RGB ¶
Term2RGB converts terminal color code (0-255) to RGB color https://github.com/essentialkaos/ek/tree/master/fmtc#88256-colors
Example ¶
c := uint8(162) fmt.Printf("%d → %s\n", c, Term2RGB(c))
Output: 162 → RGB{R:215 G:0 B:135}
func (RGB) ToCMYK ¶
ToCMYK converts RGB color to CMYK
Example ¶
fmt.Printf("%s\n", RGB{127, 25, 75}.ToCMYK())
Output: CMYK{C:0% M:80% Y:41% K:50%}
func (RGB) ToHSL ¶
ToHSL converts RGB color to HSL
Example ¶
fmt.Printf("%s\n", RGB{127, 25, 75}.ToHSL())
Output: HSL{H:331° S:67% L:30% A:0%}
func (RGB) ToHSV ¶
ToHSV converts RGB color to HSV
Example ¶
fmt.Printf("%s\n", RGB{127, 25, 75}.ToHSV())
Output: HSV{H:331° S:80% V:50% A:0%}
type RGBA ¶
func Hex2RGBA ¶
Hex2RGBA converts Hex color to RGBA
Example ¶
fmt.Printf("%s\n", Hex2RGBA(NewHex(0x7F194BCC)))
Output: RGBA{R:127 G:25 B:75 A:0.80}