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(0x222222, 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 ¶
type HSV ¶
type Hex ¶
type Hex uint32 // Hex color 0x00000000 - 0xFFFFFFFF
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))
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))
Output: #7F194BCC
func (Hex) IsRGBA ¶
IsRGBA returns true if color contains info about alpha channel
Example ¶
c1 := Hex(0x7F194B) c2 := Hex(0x7F194B5F) fmt.Printf("%s → %t\n", c1.ToWeb(true), c1.IsRGBA()) fmt.Printf("%s → %t\n", c2.ToWeb(true), c2.IsRGBA())
Output: #7F194B → false #7F194B5F → true
func (Hex) ToRGB ¶
ToRGB converts hex color to RGB
Example ¶
fmt.Printf("%s\n", Hex(0x7F194B).ToRGB())
Output: RGB{R:127 G:25 B:75}
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{331.0 / 360.0, 67.0 / 100.0, 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{331.0 / 360.0, 80.0 / 100.0, 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(0x7F194B))
Output: RGB{R:127 G:25 B:75}
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%}
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%}
Click to show internal directories.
Click to hide internal directories.