Color

package
v0.0.0-...-08a4b47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package Color provides a color represented in RGBA format.

Index

Constants

This section is empty.

Variables

View Source
var Transparent = RGBA{}
View Source
var W3C = X11
View Source
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

func AsABGR32(c RGBA) uint32

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

func AsABGR64(c RGBA) uint64

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

func AsARGB32(c RGBA) uint32

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

func AsARGB64(c RGBA) uint64

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

func AsHex(c RGBA) string

AsHex returns the color converted to an HTML hexadecimal color String in RGBA format without the hash (#) prefix.

func AsRGBA32

func AsRGBA32(c RGBA) uint32

AsRGBA32 returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits).

func AsRGBA64

func AsRGBA64(c RGBA) int64

AsRGBA64 returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits).

func AsUint32

func AsUint32(c RGBA) uint32

AsUint32 returns the color as a 32-bit RGBA integer.

func IsApproximatelyEqual

func IsApproximatelyEqual(a, b RGBA) bool

IsApproximatelyEqual returns true if this color and to are approximately equal.

func Less

func Less(a, b RGBA) bool

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

func Luminance(c RGBA) Float.X

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.

func ValidHex

func ValidHex(color string) bool

ValidHex returns true if color is a valid HTML hexadecimal color string. The string must be a hexadecimal value (case-insensitive) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign (#).

Types

type RGBA

type RGBA = struct {
	R Float.X
	G Float.X
	B Float.X
	A Float.X
}

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 Add

func Add(a, b RGBA) RGBA

func AddX

func AddX[X Float.Any | Int.Any](a RGBA, b X) RGBA

func Blend

func Blend(a, b RGBA) RGBA

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

func Bytes(r, g, b, a byte) RGBA

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

func Clamp(c RGBA, minimum, maximum RGBA) RGBA

Clamp returns a new color with all components clamped between the components of minimum and maximum.

func Darkened

func Darkened(c RGBA, amount Float.X) RGBA

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 Div

func Div(a, b RGBA) RGBA

func DivX

func DivX[X Float.Any | Int.Any](a RGBA, b X) RGBA

func HSL

func HSL(h, s, l float64) RGBA

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

func HSLA(h, s, l, a float64) RGBA

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

func HSV(h, s, v Float.X) RGBA

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

func HSVA(h, s, v, a Float.X) RGBA

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

func Hex(rgba string) RGBA

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

func Inverted(c RGBA) RGBA

Inverted returns the color with its r, g, and b components inverted ((1 - r, 1 - g, 1 - b, a)).

func Lerp

func Lerp(a, b RGBA, weight Float.X) RGBA

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

func Lightened(c RGBA, amount Float.X) RGBA

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 Mul

func Mul(a, b RGBA) RGBA

func MulX

func MulX[X Float.Any | Int.Any](a RGBA, b X) RGBA

func Neg

func Neg(a RGBA) RGBA

func RGBE9995

func RGBE9995(rgbe uint32) RGBA

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

func String(s string) RGBA

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 Sub

func Sub(a, b RGBA) RGBA

func SubX

func SubX[X Float.Any | Int.Any](a RGBA, b X) RGBA

func ToLinear

func ToLinear(c RGBA) RGBA

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

func ToSRGB(c RGBA) RGBA

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.

func Uint32

func Uint32(hex uint32) RGBA

Uint32 returns the Color associated with the provided hex integer in 32-bit RGBA format (8 bits per channel).

The int is best visualized with hexadecimal notation ("0x" prefix, making it "0xRRGGBBAA").

func Uint64

func Uint64(hex int64) RGBA

Uint64 returns the Color associated with the provided hex integer in 64-bit RGBA format (16 bits per channel).

The int is best visualized with hexadecimal notation ("0x" prefix, making it "0xRRRRGGGGBBBBAAAA").

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL