Documentation
¶
Overview ¶
Package Color provides a color represented in RGBA format.
Index ¶
- Variables
- func AsABGR32(c RGBA) uint32
- func AsABGR64(c RGBA) uint64
- func AsARGB32(c RGBA) uint32
- func AsARGB64(c RGBA) uint64
- func AsHex(c RGBA) string
- func AsRGBA32(c RGBA) uint32
- func AsRGBA64(c RGBA) int64
- func AsUint32(c RGBA) uint32
- func IsApproximatelyEqual(a, b RGBA) bool
- func Less(a, b RGBA) bool
- func Luminance(c RGBA) Float.X
- func ValidHex(color string) bool
- type RGBA
- func Add(a, b RGBA) RGBA
- func AddX[X Float.Any | Int.Any](a RGBA, b X) RGBA
- func Blend(a, b RGBA) RGBA
- func Bytes(r, g, b, a byte) RGBA
- func Clamp(c RGBA, minimum, maximum RGBA) RGBA
- func Darkened(c RGBA, amount Float.X) RGBA
- func Div(a, b RGBA) RGBA
- func DivX[X Float.Any | Int.Any](a RGBA, b X) RGBA
- func HSL(h, s, l float64) RGBA
- func HSLA(h, s, l, a float64) RGBA
- func HSV(h, s, v Float.X) RGBA
- func HSVA(h, s, v, a Float.X) RGBA
- func Hex(rgba string) RGBA
- func Inverted(c RGBA) RGBA
- func Lerp(a, b RGBA, weight Float.X) RGBA
- func Lightened(c RGBA, amount Float.X) RGBA
- func Mul(a, b RGBA) RGBA
- func MulX[X Float.Any | Int.Any](a RGBA, b X) RGBA
- func Neg(a RGBA) RGBA
- func RGBE9995(rgbe uint32) RGBA
- func String(s string) RGBA
- func Sub(a, b RGBA) RGBA
- func SubX[X Float.Any | Int.Any](a RGBA, b X) RGBA
- func ToLinear(c RGBA) RGBA
- func ToSRGB(c RGBA) RGBA
- func Uint32(hex uint32) RGBA
- func Uint64(hex int64) RGBA
Constants ¶
This section is empty.
Variables ¶
var Transparent = RGBA{}
var W3C = X11
var X11 = struct { AliceBlue, AntiqueWhite, Aqua, AquaMarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, FireBrick, FloralWhite, ForestGreen, Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrod, LightGray, LightGreen, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, NavyBlue, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, RebeccaPurple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen RGBA }{}/* 140 elements not displayed */
Functions ¶
func AsABGR32 ¶
AsABGR32 returns the color converted to a 32-bit integer in ABGR format (each component is 8 bits). ABGR is the reversed version of the default RGBA format.
func AsABGR64 ¶
AsABGR64 returns the color converted to a 64-bit integer in ABGR format (each component is 16 bits). ABGR is the reversed version of the default RGBA format.
func AsARGB32 ¶
AsARGB32 returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.
func AsARGB64 ¶
AsARGB64 returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.
func AsHex ¶
AsHex returns the color converted to an HTML hexadecimal color String in RGBA format without the hash (#) prefix.
func AsRGBA32 ¶
AsRGBA32 returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits).
func AsRGBA64 ¶
AsRGBA64 returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits).
func IsApproximatelyEqual ¶
IsApproximatelyEqual returns true if this color and to are approximately equal.
func Less ¶
Less compares two colors by first checking if the R value of the left color is less than the R value of the right color. If the R values are exactly equal, then it repeats this check with the G values of the two colors, B values of the two colors, and then with the A values. This operator is useful for sorting colors.
Note: Colors with NaN elements don't behave the same as other colors. Therefore, the results from this operator may not be accurate if NaNs are included.
func Luminance ¶
Luminance returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). This is useful when determining light or dark color. Colors with a luminance smaller than 0.5 can be generally considered dark.
Note: Luminance relies on the color being in the linear color space to return an accurate relative luminance value. If the color is in the sRGB color space, use srgb_to_linear to convert it to the linear color space first.
Types ¶
type RGBA ¶
A color represented in RGBA format by a red (r), green (g), blue (b), and alpha (a) component. Each component is a 32-bit floating-point value, usually ranging from 0.0 to 1.0. In some cases, it may support values greater than 1.0, for overbright or HDR (High Dynamic Range) colors.
func Blend ¶
Blend returns a new color resulting from overlaying this color over the given color. In a painting program, you can imagine it as the over color painted over this color (including alpha).
func Bytes ¶
Bytes returns a color represented in RGBA format by a red (r), green (g), blue (b), and alpha (a) bytes from 0 to 255.
func Clamp ¶
Clamp returns a new color with all components clamped between the components of minimum and maximum.
func Darkened ¶
Darkened returns a new color resulting from making this color darker by the specified amount (ratio from 0.0 to 1.0). See also Lightened.
func HSL ¶
HSL constructs a color from an OK HSL profile. The hue (h), saturation (s), and lightness (l) are typically between 0.0 and 1.0.
func HSLA ¶
HSLA constructs a color from an OK HSL profile. The hue (h), saturation (s), and lightness (l) are typically between 0.0 and 1.0. Includes Alpha.
func HSV ¶
HSV constructs a color from an HSV profile. The hue (h), saturation (s), and value (v) are typically between 0.0 and 1.0.
func HSVA ¶
HSVA constructs a color from an HSV profile. The hue (h), saturation (s), and value (v) are typically between 0.0 and 1.0. Includes alpha.
func Hex ¶
Hex returns a new color from rgba, an HTML hexadecimal color string. rgba is not case-sensitive and may be prefixed by a hash sign (#).
rgba must be a valid three-digit or six-digit hexadecimal color string, and may contain an alpha channel value. If rgba does not contain an alpha channel value, an alpha channel value of 1.0 is applied. If rgba is invalid, returns an empty color.
func Inverted ¶
Inverted returns the color with its r, g, and b components inverted ((1 - r, 1 - g, 1 - b, a)).
func Lerp ¶
Lerp returns the linear interpolation between this color's components and to's components. The interpolation factor weight should be between 0.0 and 1.0 (inclusive).
func Lightened ¶
Lightened returns a new color resulting from making this color lighter by the specified amount which should be a ratio from 0.0 to 1.0. See also Darkened.
func RGBE9995 ¶
RGBE9995 decodes a Color from a RGBE9995 format integer where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
func String ¶
String creates a Color from the given string, which can be either an HTML color code or a named color (case-insensitive). Returns Transparent if the color cannot be inferred from the string.
func ToLinear ¶
ToLinear returns the color converted to the linear color space. This method assumes the original color already is in the sRGB color space. See also [SRGB] which performs the opposite operation.
func ToSRGB ¶
ToSRGB returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also [Color.Linear] which performs the opposite operation.