Documentation ¶
Overview ¶
Package colors provides named colors, utilities for manipulating colors, and Material Design 3 color schemes, palettes, and keys in Go.
Index ¶
- Variables
- func Add(c, dc color.Color) color.RGBA
- func AlphaBlend(dst, src color.Color) color.RGBA
- func ApplyOpacity(c color.Color, opacity float32) color.RGBA
- func ApplyOpacityNRGBA(c color.Color, opacity float32) color.NRGBA
- func AsHex(c color.Color) string
- func AsRGBA(c color.Color) color.RGBA
- func AsString(c color.Color) string
- func Blend(bt BlendTypes, p float32, x, y color.Color) color.RGBA
- func BlendRGB(pct float32, x, y color.Color) color.RGBA
- func Clearer(c color.Color, amount float32) color.RGBA
- func FromAny(val any, base ...color.Color) (color.RGBA, error)
- func FromFloat32(r, g, b, a float32) color.RGBA
- func FromFloat64(r, g, b, a float64) color.RGBA
- func FromHex(hex string) (color.RGBA, error)
- func FromNRGBA(r, g, b, a uint8) color.RGBA
- func FromNRGBAF32(r, g, b, a float32) color.RGBA
- func FromName(name string) (color.RGBA, error)
- func FromRGB(r, g, b uint8) color.RGBA
- func FromRGBAF32(r, g, b, a float32) color.RGBA
- func FromString(str string, base ...color.Color) (color.RGBA, error)
- func Inverse(c color.Color) color.RGBA
- func IsNil(c color.Color) bool
- func Opaquer(c color.Color, amount float32) color.RGBA
- func Pattern(f func(x, y int) color.Color) image.Image
- func SetScheme(isDark bool)
- func SetSchemes(primary color.RGBA)
- func SetSchemesFromKey(key *matcolor.Key)
- func Spaced(idx int) color.RGBA
- func Sub(c, dc color.Color) color.RGBA
- func ToBase(c color.Color) color.RGBA
- func ToContainer(c color.Color) color.RGBA
- func ToFloat32(c color.Color) (r, g, b, a float32)
- func ToFloat64(c color.Color) (r, g, b, a float64)
- func ToOn(c color.Color) color.RGBA
- func ToOnContainer(c color.Color) color.RGBA
- func ToUniform(img image.Image) color.RGBA
- func Uniform(c color.Color) image.Image
- func WithA(c color.Color, a uint8) color.RGBA
- func WithAF32(c color.Color, a float32) color.RGBA
- func WithB(c color.Color, b uint8) color.RGBA
- func WithG(c color.Color, g uint8) color.RGBA
- func WithR(c color.Color, r uint8) color.RGBA
- type BlendTypes
- func (i BlendTypes) Desc() string
- func (i BlendTypes) Int64() int64
- func (i BlendTypes) MarshalText() ([]byte, error)
- func (i *BlendTypes) SetInt64(in int64)
- func (i *BlendTypes) SetString(s string) error
- func (i BlendTypes) String() string
- func (i *BlendTypes) UnmarshalText(text []byte) error
- func (i BlendTypes) Values() []enums.Enum
- type Context
- type NRGBAF32
- type RGBAF32
Examples ¶
- Add
- AlphaBlend
- ApplyOpacity
- AsHex
- AsHex (WithA)
- AsRGBA
- AsString
- Blend (Cam16)
- Blend (Hct)
- Blend (Rgb)
- BlendRGB
- Clearer
- FromAny
- FromAny (Error)
- FromHex
- FromHex (Error)
- FromHex (Lower)
- FromHex (Opacity)
- FromHex (Short)
- FromHex (ShortLower)
- FromNRGBA
- FromName
- FromName (Error)
- FromRGB
- FromString (Blend)
- FromString (Darken)
- FromString (Error)
- FromString (Hct)
- FromString (Hcta)
- FromString (Hex)
- FromString (Hsl)
- FromString (Hsla)
- FromString (Name)
- FromString (Rgb)
- FromString (Rgba)
- Inverse
- IsNil (False)
- IsNil (True)
- Opaquer
- Sub
- WithA
- WithAF32
- WithB
- WithG
- WithR
Constants ¶
This section is empty.
Variables ¶
var ( // RGBAF32Model is the model for converting colors to [RGBAF32] colors RGBAF32Model color.Model = color.ModelFunc(rgbaf32Model) // NRGBAF32Model is the model for converting colors to [NRGBAF32] colors NRGBAF32Model color.Model = color.ModelFunc(nrgbaf32Model) )
var ( Aliceblue = color.RGBA{0xf0, 0xf8, 0xff, 0xff} // rgb(240, 248, 255) Antiquewhite = color.RGBA{0xfa, 0xeb, 0xd7, 0xff} // rgb(250, 235, 215) Aqua = color.RGBA{0x00, 0xff, 0xff, 0xff} // rgb(0, 255, 255) Aquamarine = color.RGBA{0x7f, 0xff, 0xd4, 0xff} // rgb(127, 255, 212) Azure = color.RGBA{0xf0, 0xff, 0xff, 0xff} // rgb(240, 255, 255) Beige = color.RGBA{0xf5, 0xf5, 0xdc, 0xff} // rgb(245, 245, 220) Bisque = color.RGBA{0xff, 0xe4, 0xc4, 0xff} // rgb(255, 228, 196) Black = color.RGBA{0x00, 0x00, 0x00, 0xff} // rgb(0, 0, 0) Blanchedalmond = color.RGBA{0xff, 0xeb, 0xcd, 0xff} // rgb(255, 235, 205) Blue = color.RGBA{0x00, 0x00, 0xff, 0xff} // rgb(0, 0, 255) Blueviolet = color.RGBA{0x8a, 0x2b, 0xe2, 0xff} // rgb(138, 43, 226) Brown = color.RGBA{0xa5, 0x2a, 0x2a, 0xff} // rgb(165, 42, 42) Burlywood = color.RGBA{0xde, 0xb8, 0x87, 0xff} // rgb(222, 184, 135) Cadetblue = color.RGBA{0x5f, 0x9e, 0xa0, 0xff} // rgb(95, 158, 160) Chartreuse = color.RGBA{0x7f, 0xff, 0x00, 0xff} // rgb(127, 255, 0) Chocolate = color.RGBA{0xd2, 0x69, 0x1e, 0xff} // rgb(210, 105, 30) Coral = color.RGBA{0xff, 0x7f, 0x50, 0xff} // rgb(255, 127, 80) Cornflowerblue = color.RGBA{0x64, 0x95, 0xed, 0xff} // rgb(100, 149, 237) Cornsilk = color.RGBA{0xff, 0xf8, 0xdc, 0xff} // rgb(255, 248, 220) Crimson = color.RGBA{0xdc, 0x14, 0x3c, 0xff} // rgb(220, 20, 60) Cyan = color.RGBA{0x00, 0xff, 0xff, 0xff} // rgb(0, 255, 255) Darkblue = color.RGBA{0x00, 0x00, 0x8b, 0xff} // rgb(0, 0, 139) Darkcyan = color.RGBA{0x00, 0x8b, 0x8b, 0xff} // rgb(0, 139, 139) Darkgoldenrod = color.RGBA{0xb8, 0x86, 0x0b, 0xff} // rgb(184, 134, 11) Darkgray = color.RGBA{0xa9, 0xa9, 0xa9, 0xff} // rgb(169, 169, 169) Darkgreen = color.RGBA{0x00, 0x64, 0x00, 0xff} // rgb(0, 100, 0) Darkgrey = color.RGBA{0xa9, 0xa9, 0xa9, 0xff} // rgb(169, 169, 169) Darkkhaki = color.RGBA{0xbd, 0xb7, 0x6b, 0xff} // rgb(189, 183, 107) Darkmagenta = color.RGBA{0x8b, 0x00, 0x8b, 0xff} // rgb(139, 0, 139) Darkolivegreen = color.RGBA{0x55, 0x6b, 0x2f, 0xff} // rgb(85, 107, 47) Darkorange = color.RGBA{0xff, 0x8c, 0x00, 0xff} // rgb(255, 140, 0) Darkorchid = color.RGBA{0x99, 0x32, 0xcc, 0xff} // rgb(153, 50, 204) Darkred = color.RGBA{0x8b, 0x00, 0x00, 0xff} // rgb(139, 0, 0) Darksalmon = color.RGBA{0xe9, 0x96, 0x7a, 0xff} // rgb(233, 150, 122) Darkseagreen = color.RGBA{0x8f, 0xbc, 0x8f, 0xff} // rgb(143, 188, 143) Darkslateblue = color.RGBA{0x48, 0x3d, 0x8b, 0xff} // rgb(72, 61, 139) Darkslategray = color.RGBA{0x2f, 0x4f, 0x4f, 0xff} // rgb(47, 79, 79) Darkslategrey = color.RGBA{0x2f, 0x4f, 0x4f, 0xff} // rgb(47, 79, 79) Darkturquoise = color.RGBA{0x00, 0xce, 0xd1, 0xff} // rgb(0, 206, 209) Darkviolet = color.RGBA{0x94, 0x00, 0xd3, 0xff} // rgb(148, 0, 211) Deeppink = color.RGBA{0xff, 0x14, 0x93, 0xff} // rgb(255, 20, 147) Deepskyblue = color.RGBA{0x00, 0xbf, 0xff, 0xff} // rgb(0, 191, 255) Dimgray = color.RGBA{0x69, 0x69, 0x69, 0xff} // rgb(105, 105, 105) Dimgrey = color.RGBA{0x69, 0x69, 0x69, 0xff} // rgb(105, 105, 105) Dodgerblue = color.RGBA{0x1e, 0x90, 0xff, 0xff} // rgb(30, 144, 255) Firebrick = color.RGBA{0xb2, 0x22, 0x22, 0xff} // rgb(178, 34, 34) Floralwhite = color.RGBA{0xff, 0xfa, 0xf0, 0xff} // rgb(255, 250, 240) Forestgreen = color.RGBA{0x22, 0x8b, 0x22, 0xff} // rgb(34, 139, 34) Fuchsia = color.RGBA{0xff, 0x00, 0xff, 0xff} // rgb(255, 0, 255) Gainsboro = color.RGBA{0xdc, 0xdc, 0xdc, 0xff} // rgb(220, 220, 220) Ghostwhite = color.RGBA{0xf8, 0xf8, 0xff, 0xff} // rgb(248, 248, 255) Gold = color.RGBA{0xff, 0xd7, 0x00, 0xff} // rgb(255, 215, 0) Goldenrod = color.RGBA{0xda, 0xa5, 0x20, 0xff} // rgb(218, 165, 32) Gray = color.RGBA{0x80, 0x80, 0x80, 0xff} // rgb(128, 128, 128) Green = color.RGBA{0x00, 0x80, 0x00, 0xff} // rgb(0, 128, 0) Greenyellow = color.RGBA{0xad, 0xff, 0x2f, 0xff} // rgb(173, 255, 47) Grey = color.RGBA{0x80, 0x80, 0x80, 0xff} // rgb(128, 128, 128) Honeydew = color.RGBA{0xf0, 0xff, 0xf0, 0xff} // rgb(240, 255, 240) Hotpink = color.RGBA{0xff, 0x69, 0xb4, 0xff} // rgb(255, 105, 180) Indianred = color.RGBA{0xcd, 0x5c, 0x5c, 0xff} // rgb(205, 92, 92) Indigo = color.RGBA{0x4b, 0x00, 0x82, 0xff} // rgb(75, 0, 130) Ivory = color.RGBA{0xff, 0xff, 0xf0, 0xff} // rgb(255, 255, 240) Khaki = color.RGBA{0xf0, 0xe6, 0x8c, 0xff} // rgb(240, 230, 140) Lavender = color.RGBA{0xe6, 0xe6, 0xfa, 0xff} // rgb(230, 230, 250) Lavenderblush = color.RGBA{0xff, 0xf0, 0xf5, 0xff} // rgb(255, 240, 245) Lawngreen = color.RGBA{0x7c, 0xfc, 0x00, 0xff} // rgb(124, 252, 0) Lemonchiffon = color.RGBA{0xff, 0xfa, 0xcd, 0xff} // rgb(255, 250, 205) Lightblue = color.RGBA{0xad, 0xd8, 0xe6, 0xff} // rgb(173, 216, 230) Lightcoral = color.RGBA{0xf0, 0x80, 0x80, 0xff} // rgb(240, 128, 128) Lightcyan = color.RGBA{0xe0, 0xff, 0xff, 0xff} // rgb(224, 255, 255) Lightgoldenrodyellow = color.RGBA{0xfa, 0xfa, 0xd2, 0xff} // rgb(250, 250, 210) Lightgray = color.RGBA{0xd3, 0xd3, 0xd3, 0xff} // rgb(211, 211, 211) Lightgreen = color.RGBA{0x90, 0xee, 0x90, 0xff} // rgb(144, 238, 144) Lightgrey = color.RGBA{0xd3, 0xd3, 0xd3, 0xff} // rgb(211, 211, 211) Lightpink = color.RGBA{0xff, 0xb6, 0xc1, 0xff} // rgb(255, 182, 193) Lightsalmon = color.RGBA{0xff, 0xa0, 0x7a, 0xff} // rgb(255, 160, 122) Lightseagreen = color.RGBA{0x20, 0xb2, 0xaa, 0xff} // rgb(32, 178, 170) Lightskyblue = color.RGBA{0x87, 0xce, 0xfa, 0xff} // rgb(135, 206, 250) Lightslategray = color.RGBA{0x77, 0x88, 0x99, 0xff} // rgb(119, 136, 153) Lightslategrey = color.RGBA{0x77, 0x88, 0x99, 0xff} // rgb(119, 136, 153) Lightsteelblue = color.RGBA{0xb0, 0xc4, 0xde, 0xff} // rgb(176, 196, 222) Lightyellow = color.RGBA{0xff, 0xff, 0xe0, 0xff} // rgb(255, 255, 224) Lime = color.RGBA{0x00, 0xff, 0x00, 0xff} // rgb(0, 255, 0) Limegreen = color.RGBA{0x32, 0xcd, 0x32, 0xff} // rgb(50, 205, 50) Linen = color.RGBA{0xfa, 0xf0, 0xe6, 0xff} // rgb(250, 240, 230) Magenta = color.RGBA{0xff, 0x00, 0xff, 0xff} // rgb(255, 0, 255) Maroon = color.RGBA{0x80, 0x00, 0x00, 0xff} // rgb(128, 0, 0) Mediumaquamarine = color.RGBA{0x66, 0xcd, 0xaa, 0xff} // rgb(102, 205, 170) Mediumblue = color.RGBA{0x00, 0x00, 0xcd, 0xff} // rgb(0, 0, 205) Mediumorchid = color.RGBA{0xba, 0x55, 0xd3, 0xff} // rgb(186, 85, 211) Mediumpurple = color.RGBA{0x93, 0x70, 0xdb, 0xff} // rgb(147, 112, 219) Mediumseagreen = color.RGBA{0x3c, 0xb3, 0x71, 0xff} // rgb(60, 179, 113) Mediumslateblue = color.RGBA{0x7b, 0x68, 0xee, 0xff} // rgb(123, 104, 238) Mediumspringgreen = color.RGBA{0x00, 0xfa, 0x9a, 0xff} // rgb(0, 250, 154) Mediumturquoise = color.RGBA{0x48, 0xd1, 0xcc, 0xff} // rgb(72, 209, 204) Mediumvioletred = color.RGBA{0xc7, 0x15, 0x85, 0xff} // rgb(199, 21, 133) Midnightblue = color.RGBA{0x19, 0x19, 0x70, 0xff} // rgb(25, 25, 112) Mintcream = color.RGBA{0xf5, 0xff, 0xfa, 0xff} // rgb(245, 255, 250) Mistyrose = color.RGBA{0xff, 0xe4, 0xe1, 0xff} // rgb(255, 228, 225) Moccasin = color.RGBA{0xff, 0xe4, 0xb5, 0xff} // rgb(255, 228, 181) Oldlace = color.RGBA{0xfd, 0xf5, 0xe6, 0xff} // rgb(253, 245, 230) Olive = color.RGBA{0x80, 0x80, 0x00, 0xff} // rgb(128, 128, 0) Olivedrab = color.RGBA{0x6b, 0x8e, 0x23, 0xff} // rgb(107, 142, 35) Orange = color.RGBA{0xff, 0xa5, 0x00, 0xff} // rgb(255, 165, 0) Orangered = color.RGBA{0xff, 0x45, 0x00, 0xff} // rgb(255, 69, 0) Orchid = color.RGBA{0xda, 0x70, 0xd6, 0xff} // rgb(218, 112, 214) Palegoldenrod = color.RGBA{0xee, 0xe8, 0xaa, 0xff} // rgb(238, 232, 170) Palegreen = color.RGBA{0x98, 0xfb, 0x98, 0xff} // rgb(152, 251, 152) Paleturquoise = color.RGBA{0xaf, 0xee, 0xee, 0xff} // rgb(175, 238, 238) Palevioletred = color.RGBA{0xdb, 0x70, 0x93, 0xff} // rgb(219, 112, 147) Papayawhip = color.RGBA{0xff, 0xef, 0xd5, 0xff} // rgb(255, 239, 213) Peachpuff = color.RGBA{0xff, 0xda, 0xb9, 0xff} // rgb(255, 218, 185) Peru = color.RGBA{0xcd, 0x85, 0x3f, 0xff} // rgb(205, 133, 63) Pink = color.RGBA{0xff, 0xc0, 0xcb, 0xff} // rgb(255, 192, 203) Plum = color.RGBA{0xdd, 0xa0, 0xdd, 0xff} // rgb(221, 160, 221) Powderblue = color.RGBA{0xb0, 0xe0, 0xe6, 0xff} // rgb(176, 224, 230) Purple = color.RGBA{0x80, 0x00, 0x80, 0xff} // rgb(128, 0, 128) Rebeccapurple = color.RGBA{0x66, 0x33, 0x99, 0xff} // rgb(102, 51, 153) Red = color.RGBA{0xff, 0x00, 0x00, 0xff} // rgb(255, 0, 0) Rosybrown = color.RGBA{0xbc, 0x8f, 0x8f, 0xff} // rgb(188, 143, 143) Royalblue = color.RGBA{0x41, 0x69, 0xe1, 0xff} // rgb(65, 105, 225) Saddlebrown = color.RGBA{0x8b, 0x45, 0x13, 0xff} // rgb(139, 69, 19) Salmon = color.RGBA{0xfa, 0x80, 0x72, 0xff} // rgb(250, 128, 114) Sandybrown = color.RGBA{0xf4, 0xa4, 0x60, 0xff} // rgb(244, 164, 96) Seagreen = color.RGBA{0x2e, 0x8b, 0x57, 0xff} // rgb(46, 139, 87) Seashell = color.RGBA{0xff, 0xf5, 0xee, 0xff} // rgb(255, 245, 238) Sienna = color.RGBA{0xa0, 0x52, 0x2d, 0xff} // rgb(160, 82, 45) Silver = color.RGBA{0xc0, 0xc0, 0xc0, 0xff} // rgb(192, 192, 192) Skyblue = color.RGBA{0x87, 0xce, 0xeb, 0xff} // rgb(135, 206, 235) Slateblue = color.RGBA{0x6a, 0x5a, 0xcd, 0xff} // rgb(106, 90, 205) Slategray = color.RGBA{0x70, 0x80, 0x90, 0xff} // rgb(112, 128, 144) Slategrey = color.RGBA{0x70, 0x80, 0x90, 0xff} // rgb(112, 128, 144) Snow = color.RGBA{0xff, 0xfa, 0xfa, 0xff} // rgb(255, 250, 250) Springgreen = color.RGBA{0x00, 0xff, 0x7f, 0xff} // rgb(0, 255, 127) Steelblue = color.RGBA{0x46, 0x82, 0xb4, 0xff} // rgb(70, 130, 180) Tan = color.RGBA{0xd2, 0xb4, 0x8c, 0xff} // rgb(210, 180, 140) Teal = color.RGBA{0x00, 0x80, 0x80, 0xff} // rgb(0, 128, 128) Thistle = color.RGBA{0xd8, 0xbf, 0xd8, 0xff} // rgb(216, 191, 216) Tomato = color.RGBA{0xff, 0x63, 0x47, 0xff} // rgb(255, 99, 71) Turquoise = color.RGBA{0x40, 0xe0, 0xd0, 0xff} // rgb(64, 224, 208) Violet = color.RGBA{0xee, 0x82, 0xee, 0xff} // rgb(238, 130, 238) Wheat = color.RGBA{0xf5, 0xde, 0xb3, 0xff} // rgb(245, 222, 179) White = color.RGBA{0xff, 0xff, 0xff, 0xff} // rgb(255, 255, 255) Whitesmoke = color.RGBA{0xf5, 0xf5, 0xf5, 0xff} // rgb(245, 245, 245) Yellow = color.RGBA{0xff, 0xff, 0x00, 0xff} // rgb(255, 255, 0) Yellowgreen = color.RGBA{0x9a, 0xcd, 0x32, 0xff} // rgb(154, 205, 50) Transparent = color.RGBA{0, 0, 0, 0} // rgb(0, 0, 0, 0) )
var Map = map[string]color.RGBA{}/* 149 elements not displayed */
Map contains named colors defined in the CSS spec.
var Names = []string{}/* 149 elements not displayed */
Names contains the color names defined in the CSS spec.
var Palette = matcolor.NewPalette(matcolor.KeyFromPrimary(color.RGBA{66, 133, 244, 255}))
Palette contains the main, global [MatPalette]. It can be used by end-user code for accessing tonal palette values, although Scheme is a more typical way to access the color scheme values. It defaults to a palette based around a primary color of Google Blue (#4285f4)
var Scheme = &Schemes.Light
Scheme is the main currently active global Material Design 3 color scheme. It is the main way that end-user code should access the color scheme; ideally, almost all color values should be set to something in here. For more specific tones of colors, see Palette. For setting the color schemes of your app, see Schemes and SetSchemes. For setting this scheme to be light or dark, see SetScheme.
var Schemes = matcolor.NewSchemes(Palette)
Schemes are the main global Material Design 3 color schemes. They should not be used for accessing the current color scheme; see Scheme for that. Instead, they should be set if you want to define your own custom color schemes for your app. The recommended way to set the Schemes is through the SetSchemes function.
Functions ¶
func Add ¶
Add adds given color deltas to this color, safely avoiding overflow > 255
Example ¶
fmt.Println(Add(Red, Blue))
Output: {255 0 255 255}
func AlphaBlend ¶
AlphaBlend blends the two colors, handling alpha blending correctly. The source color is figuratively placed "on top of" the destination color.
Example ¶
fmt.Println(AlphaBlend(Wheat, WithAF32(Blue, 0.5)))
Output: {123 111 217 255}
func ApplyOpacity ¶
ApplyOpacity applies the given opacity (0-1) to the given color and returns the result. It is different from WithAF32 in that it sets the transparency (A) value of the color to the current value times the given value instead of just directly overriding it.
Example ¶
fmt.Println(ApplyOpacity(WithAF32(Gold, 0.4), 0.3))
Output: {30 25 0 30}
func ApplyOpacityNRGBA ¶ added in v0.0.3
ApplyOpacityNRGBA applies the given opacity (0-1) to the given color and returns the result. It is different from WithAF32 in that it sets the transparency (A) value of the color to the current value times the given value instead of just directly overriding it. It is the color.NRGBA version of ApplyOpacity.
func AsHex ¶
AsHex returns the color as a standard 2-hexadecimal-digits-per-component non-alpha-premultiplied hex color string.
Example ¶
fmt.Println(AsHex(Blueviolet))
Output: #8A2BE2
Example (WithA) ¶
fmt.Println(AsHex(WithA(Red, 100)))
Output: #FF000064
func AsRGBA ¶
AsRGBA returns the given color as an RGBA color
Example ¶
fmt.Println(AsRGBA(color.Gray{50}))
Output: {50 50 50 255}
func AsString ¶
AsString returns the given color as a string, using its String method if it exists, and formatting it as rgba(r, g, b, a) otherwise.
Example ¶
fmt.Println(AsString(Orange))
Output: rgba(255, 165, 0, 255)
func Blend ¶
Blend returns a color that is the given proportion between the first and second color. For example, 0.1 indicates to blend 10% of the first color and 90% of the second. Blending is done using the given blending algorithm.
Example (Cam16) ¶
fmt.Println(Blend(CAM16, 30, Lightblue, Darkblue))
Output: {60 82 148 255}
Example (Hct) ¶
fmt.Println(Blend(HCT, 30, Lightblue, Darkblue))
Output: {51 78 160 255}
Example (Rgb) ¶
fmt.Println(Blend(RGB, 30, Lightblue, Darkblue))
Output: {52 65 166 255}
func BlendRGB ¶
BlendRGB returns a color that is the given proportion between the first and second color in RGB colorspace. For example, 0.1 indicates to blend 10% of the first color and 90% of the second. Blending is done directly on non-premultiplied RGB values, and a correctly premultiplied color is returned.
Example ¶
fmt.Println(BlendRGB(30, Lightblue, Darkblue))
Output: {52 65 166 255}
func Clearer ¶
Clearer returns a color that is the given amount more transparent (lower alpha value) in terms of RGBA absolute alpha from 0 to 100, with the color premultiplication updated.
Example ¶
fmt.Println(Clearer(Gainsboro, 20))
Output: {176 176 176 204}
func FromAny ¶
FromAny returns a color from the given value of any type. It handles values of types string, color.Color, *color.Color, image.Image, and *image.Image. It takes an optional base color for relative transformations (see FromString).
Example ¶
fmt.Println(FromAny("rgb(12, 18, 92)"))
Output: {12 18 92 255} <nil>
Example (Error) ¶
fmt.Println(FromAny([]float32{}))
Output: {0 0 0 0} colors.FromAny: could not get color from value [] of type []float32
func FromFloat32 ¶
FromFloat32 makes a new RGBA color from the given 0-1 normalized floating point numbers (alpha-premultiplied)
func FromFloat64 ¶
FromFloat64 makes a new RGBA color from the given 0-1 normalized floating point numbers (alpha-premultiplied)
func FromHex ¶
FromHex parses the given non-alpha-premultiplied hex color string and returns the resulting alpha-premultiplied color.
Example ¶
fmt.Println(FromHex("#FF00FF"))
Output: {255 0 255 255} <nil>
Example (Error) ¶
fmt.Println(FromHex("#ef"))
Output: {0 0 0 0} colors.FromHex: could not process "ef"
Example (Lower) ¶
fmt.Println(FromHex("#1abc2e"))
Output: {26 188 46 255} <nil>
Example (Opacity) ¶
fmt.Println(FromHex("#FF00FFEE"))
Output: {238 0 238 238} <nil>
Example (Short) ¶
fmt.Println(FromHex("F3A"))
Output: {255 51 170 255} <nil>
Example (ShortLower) ¶
fmt.Println(FromHex("#bb6"))
Output: {187 187 102 255} <nil>
func FromNRGBA ¶
FromNRGBA makes a new RGBA color from the given non-alpha-premultiplied RGBA uint8 values.
Example ¶
fmt.Println(FromNRGBA(50, 100, 150, 200))
Output: {39 78 118 200}
func FromNRGBAF32 ¶
FromNRGBAF32 returns the color specified by the given float32 non alpha-premultiplied RGBA values in the range 0 to 1
func FromName ¶
FromName returns the color value specified by the given CSS standard color name.
Example ¶
fmt.Println(FromName("yellowgreen"))
Output: {154 205 50 255} <nil>
Example (Error) ¶
fmt.Println(FromName("invalidcolor"))
Output: {0 0 0 0} colors.FromName: name not found: invalidcolor
func FromRGB ¶
FromRGB makes a new RGBA color from the given RGB uint8 values, using 255 for A.
Example ¶
fmt.Println(FromRGB(50, 100, 150))
Output: {50 100 150 255}
func FromRGBAF32 ¶
FromRGBAF32 returns the color specified by the given float32 alpha-premultiplied RGBA values in the range 0 to 1
func FromString ¶
FromString returns a color value from the given string. FromString accepts the following types of strings: standard color names, hex, rgb, rgba, hsl, hsla, hct, and hcta values, "none" or "off", or any of the transformations listed below. The transformations use the given single base color as their starting point; if you do not provide a base color, they will use Transparent as their starting point. The transformations are:
- currentcolor = base color
- inverse = inverse of base color
- lighten-VAL or darken-VAL: VAL is amount to lighten or darken (using HCT), e.g., lighter-10 is 10 higher tone
- saturate-VAL or desaturate-VAL: manipulates the chroma level in HCT by VAL
- spin-VAL: manipulates the hue level in HCT by VAL
- clearer-VAL or opaquer-VAL: manipulates the alpha level by VAL
- blend-VAL-color: blends given percent of given color relative to base in RGB space
Example (Blend) ¶
fmt.Println(FromString("blend-40-#fff", Black))
Output: {153 153 153 255} <nil>
Example (Darken) ¶
fmt.Println(FromString("darken-10", Green))
Output: {1 100 0 255} <nil>
Example (Error) ¶
fmt.Println(FromString("lighten-something"))
Output: {0 0 0 0} colors.FromString: error getting numeric value from "something": strconv.ParseFloat: parsing "something": invalid syntax
Example (Hct) ¶
fmt.Println(FromString("hct(240, 56, 66)"))
Output: {7 171 240 255} <nil>
Example (Hcta) ¶
fmt.Println(FromString("hcta(83, 91, 48, 233)"))
Output: {135 98 0 233} <nil>
Example (Hex) ¶
fmt.Println(FromString("#2af"))
Output: {34 170 255 255} <nil>
Example (Hsl) ¶
fmt.Println(FromString("hsl(12, 62, 50, 189)"))
Output: {154 59 35 189} <nil>
Example (Hsla) ¶
fmt.Println(FromString("hsla(12, 62, 50)"))
Output: {207 80 48 255} <nil>
Example (Name) ¶
fmt.Println(FromString("violet"))
Output: {238 130 238 255} <nil>
Example (Rgb) ¶
fmt.Println(FromString("rgb(202, 38, 16, 112)"))
Output: {89 16 7 112} <nil>
Example (Rgba) ¶
fmt.Println(FromString("rgba(188, 12, 71, 201)"))
Output: {148 9 56 201} <nil>
func Inverse ¶
Inverse returns the inverse of the given color (255 - each component). It does not change the alpha channel.
Example ¶
fmt.Println(Inverse(Limegreen))
Output: {205 50 205 255}
func IsNil ¶
IsNil returns whether the color is the nil initial default color
Example (False) ¶
fmt.Println(IsNil(Blue))
Output: false
Example (True) ¶
fmt.Println(IsNil(color.RGBA{}))
Output: true
func Opaquer ¶
Opaquer returns a color that is the given amount more opaque (higher alpha value) in terms of RGBA absolute alpha from 0 to 100, with the color premultiplication updated.
Example ¶
fmt.Println(Opaquer(WithAF32(Green, 0.15), 30))
Output: {0 57 0 114}
func Pattern ¶
Pattern returns a new unbounded image.Image represented by the given pattern function.
func SetScheme ¶
func SetScheme(isDark bool)
SetScheme sets the value of Scheme to either [Schemes.Dark] or [Schemes.Light], based on the given value of whether the color scheme should be dark. It also sets the value of matcolor.SchemeIsDark.
func SetSchemes ¶
SetSchemes sets Schemes, Scheme, and Palette based on the given primary color. It is the main way that end-user code should set the color schemes to something custom. For more specific control, see SetSchemesFromKey.
func SetSchemesFromKey ¶
SetSchemes sets Schemes, Scheme, and Palette based on the given matcolor.Key. It should be used instead of SetSchemes if you want more specific control over the color scheme.
func Spaced ¶
Spaced returns a maximally widely spaced sequence of colors for progressive values of the index, using the HCT space. This is useful, for example, for assigning colors in graphs.
func Sub ¶
Sub subtracts given color deltas from this color, safely avoiding underflow < 0
Example ¶
fmt.Println(Sub(Purple, Blue))
Output: {128 0 0 0}
func ToBase ¶ added in v0.2.0
ToBase returns the base accent color for the given color based on the current scheme (light or dark), which is typically used for high emphasis objects or text.
func ToContainer ¶ added in v0.2.0
ToContainer returns the container accent color for the given color based on the current scheme (light or dark), which is typically used for lower emphasis content.
func ToFloat32 ¶
ToFloat32 returns 0-1 normalized floating point numbers from given color (alpha-premultiplied)
func ToFloat64 ¶
ToFloat64 returns 0-1 normalized floating point numbers from given color (alpha-premultiplied)
func ToOn ¶ added in v0.2.0
ToOn returns the accent color for the given color that should be placed on top of ToBase based on the current scheme (light or dark).
func ToOnContainer ¶ added in v0.2.0
ToOnContainer returns the accent color for the given color that should be placed on top of ToContainer based on the current scheme (light or dark).
func ToUniform ¶
ToUniform converts the given image to a uniform color.RGBA color.
func Uniform ¶ added in v0.2.1
Uniform returns a new image.Uniform filled completely with the given color.
func WithA ¶
WithA returns the given color with the transparency (A) set to the given value, with the color premultiplication updated.
Example ¶
fmt.Println(WithA(Royalblue, 215))
Output: {55 88 190 215}
func WithAF32 ¶
WithAF32 returns the given color with the transparency (A) set to the given float32 value between 0 and 1, with the color premultiplication updated.
Example ¶
fmt.Println(WithAF32(Olive, 0.6))
Output: {77 77 0 153}
func WithB ¶
WithB returns the given color with the blue component (B) set to the given alpha-premultiplied value
Example ¶
fmt.Println(WithB(Pink, 100))
Output: {255 192 100 255}
Types ¶
type BlendTypes ¶
type BlendTypes int32 //enums:enum
BlendTypes are different algorithms (colorspaces) to use for blending the color stop values in generating the gradients.
const ( // HCT uses the hue, chroma, and tone space and generally produces the best results, // but at a slight performance cost. HCT BlendTypes = iota // RGB uses raw RGB space, which is the standard space that most other programs use. // It produces decent results with maximum performance. RGB // CAM16 is an alternative colorspace, similar to HCT, but not quite as good. CAM16 )
const BlendTypesN BlendTypes = 3
BlendTypesN is the highest valid value for type BlendTypes, plus one.
func BlendTypesValues ¶
func BlendTypesValues() []BlendTypes
BlendTypesValues returns all possible values for the type BlendTypes.
func (BlendTypes) Desc ¶
func (i BlendTypes) Desc() string
Desc returns the description of the BlendTypes value.
func (BlendTypes) Int64 ¶
func (i BlendTypes) Int64() int64
Int64 returns the BlendTypes value as an int64.
func (BlendTypes) MarshalText ¶
func (i BlendTypes) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*BlendTypes) SetInt64 ¶
func (i *BlendTypes) SetInt64(in int64)
SetInt64 sets the BlendTypes value from an int64.
func (*BlendTypes) SetString ¶
func (i *BlendTypes) SetString(s string) error
SetString sets the BlendTypes value from its string representation, and returns an error if the string is invalid.
func (BlendTypes) String ¶
func (i BlendTypes) String() string
String returns the string representation of this BlendTypes value.
func (*BlendTypes) UnmarshalText ¶
func (i *BlendTypes) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (BlendTypes) Values ¶
func (i BlendTypes) Values() []enums.Enum
Values returns all possible values for the type BlendTypes.
type Context ¶
type Context interface { // Base returns the base color that the color parsing is relative top Base() color.RGBA // ImageByURL returns the [image.Image] associated with the given URL. // Typical URL formats are HTTP URLs like "https://example.com" and node // URLs like "#name". If it returns nil, that indicats that there is no // [image.Image] color associated with the given URL. ImageByURL(url string) image.Image }
Context contains information about the context in which color parsing occurs.
type NRGBAF32 ¶
type NRGBAF32 struct {
R, G, B, A float32
}
NRGBAF32 stores non-alpha-premultiplied RGBA values in a float32 0 to 1 normalized format, which is more useful for converting to other spaces
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cam
|
|
Package gradient provides linear, radial, and conic color gradients.
|
Package gradient provides linear, radial, and conic color gradients. |
Package matcolor provides support for creating Material Design 3 color schemes and palettes.
|
Package matcolor provides support for creating Material Design 3 color schemes and palettes. |