blcolor

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: AGPL-3.0 Imports: 10 Imported by: 4

Documentation

Overview

Package blcolor contains color creation and manipulation tools.

Package blcolor contains color creation and manipulation tools.

Package blcolor contains color creation and manipulation tools.

Package blcolor contains color creation and manipulation tools.

Index

Constants

This section is empty.

Variables

View Source
var (
	Blueviolet           = RGBHex(138, 43, 226)
	Brown                = RGBHex(165, 42, 42)
	Aliceblue            = RGBHex(240, 248, 255)
	Antiquewhite         = RGBHex(250, 235, 215)
	Aqua                 = RGBHex(0, 255, 255)
	Aquamarine           = RGBHex(127, 255, 212)
	Azure                = RGBHex(240, 255, 255)
	Beige                = RGBHex(245, 245, 220)
	Bisque               = RGBHex(255, 228, 196)
	Black                = RGBHex(0, 0, 0)
	Blanchedalmond       = RGBHex(255, 235, 205)
	Blue                 = RGBHex(0, 0, 255)
	Burlywood            = RGBHex(222, 184, 135)
	Cadetblue            = RGBHex(95, 158, 160)
	Chartreuse           = RGBHex(127, 255, 0)
	Chocolate            = RGBHex(210, 105, 30)
	Coral                = RGBHex(255, 127, 80)
	Cornflowerblue       = RGBHex(100, 149, 237)
	Cornsilk             = RGBHex(255, 248, 220)
	Crimson              = RGBHex(220, 20, 60)
	Cyan                 = RGBHex(0, 255, 255)
	Darkblue             = RGBHex(0, 0, 139)
	Darkcyan             = RGBHex(0, 139, 139)
	Darkgoldenrod        = RGBHex(184, 134, 11)
	Darkgray             = RGBHex(169, 169, 169)
	Darkgreen            = RGBHex(0, 100, 0)
	Darkgrey             = RGBHex(169, 169, 169)
	Darkkhaki            = RGBHex(189, 183, 107)
	Darkmagenta          = RGBHex(139, 0, 139)
	Darkolivegreen       = RGBHex(85, 107, 47)
	Darkorange           = RGBHex(255, 140, 0)
	Darkorchid           = RGBHex(153, 50, 204)
	Darkred              = RGBHex(139, 0, 0)
	Darksalmon           = RGBHex(233, 150, 122)
	Darkseagreen         = RGBHex(143, 188, 143)
	Darkslateblue        = RGBHex(72, 61, 139)
	Darkslategray        = RGBHex(47, 79, 79)
	Darkslategrey        = RGBHex(47, 79, 79)
	Darkturquoise        = RGBHex(0, 206, 209)
	Darkviolet           = RGBHex(148, 0, 211)
	Deeppink             = RGBHex(255, 20, 147)
	Deepskyblue          = RGBHex(0, 191, 255)
	Dimgray              = RGBHex(105, 105, 105)
	Dimgrey              = RGBHex(105, 105, 105)
	Dodgerblue           = RGBHex(30, 144, 255)
	Firebrick            = RGBHex(178, 34, 34)
	Floralwhite          = RGBHex(255, 250, 240)
	Forestgreen          = RGBHex(34, 139, 34)
	Fuchsia              = RGBHex(255, 0, 255)
	Gainsboro            = RGBHex(220, 220, 220)
	Ghostwhite           = RGBHex(248, 248, 255)
	Gold                 = RGBHex(255, 215, 0)
	Goldenrod            = RGBHex(218, 165, 32)
	Gray                 = RGBHex(128, 128, 128)
	Green                = RGBHex(0, 128, 0)
	Greenyellow          = RGBHex(173, 255, 47)
	Honeydew             = RGBHex(240, 255, 240)
	Hotpink              = RGBHex(255, 105, 180)
	Indianred            = RGBHex(205, 92, 92)
	Indigo               = RGBHex(75, 0, 130)
	Ivory                = RGBHex(255, 255, 240)
	Khaki                = RGBHex(240, 230, 140)
	Lavender             = RGBHex(230, 230, 250)
	Lavenderblush        = RGBHex(255, 240, 245)
	Lawngreen            = RGBHex(124, 252, 0)
	Lemonchiffon         = RGBHex(255, 250, 205)
	Lightblue            = RGBHex(173, 216, 230)
	Lightcoral           = RGBHex(240, 128, 128)
	Lightcyan            = RGBHex(224, 255, 255)
	Lightgoldenrodyellow = RGBHex(250, 250, 210)
	Lightgray            = RGBHex(211, 211, 211)
	Lightgreen           = RGBHex(144, 238, 144)
	Lightgrey            = RGBHex(211, 211, 211)
	Lightpink            = RGBHex(255, 182, 193)
	Lightsalmon          = RGBHex(255, 160, 122)
	Lightseagreen        = RGBHex(32, 178, 170)
	Lightskyblue         = RGBHex(135, 206, 250)
	Lightslategray       = RGBHex(119, 136, 153)
	Lightslategrey       = RGBHex(119, 136, 153)
	Lightsteelblue       = RGBHex(176, 196, 222)
	Lightyellow          = RGBHex(255, 255, 224)
	Lime                 = RGBHex(0, 255, 0)
	Limegreen            = RGBHex(50, 205, 50)
	Linen                = RGBHex(250, 240, 230)
	Magenta              = RGBHex(255, 0, 255)
	Maroon               = RGBHex(128, 0, 0)
	Mediumaquamarine     = RGBHex(102, 205, 170)
	Mediumblue           = RGBHex(0, 0, 205)
	Mediumorchid         = RGBHex(186, 85, 211)
	Mediumpurple         = RGBHex(147, 112, 219)
	Mediumseagreen       = RGBHex(60, 179, 113)
	Mediumslateblue      = RGBHex(123, 104, 238)
	Mediumspringgreen    = RGBHex(0, 250, 154)
	Mediumturquoise      = RGBHex(72, 209, 204)
	Mediumvioletred      = RGBHex(199, 21, 133)
	Midnightblue         = RGBHex(25, 25, 112)
	Mintcream            = RGBHex(245, 255, 250)
	Mistyrose            = RGBHex(255, 228, 225)
	Moccasin             = RGBHex(255, 228, 181)
	Navajowhite          = RGBHex(255, 222, 173)
	Navy                 = RGBHex(0, 0, 128)
	Oldlace              = RGBHex(253, 245, 230)
	Olive                = RGBHex(128, 128, 0)
	Olivedrab            = RGBHex(107, 142, 35)
	Orange               = RGBHex(255, 165, 0)
	Orangered            = RGBHex(255, 69, 0)
	Orchid               = RGBHex(218, 112, 214)
	Palegoldenrod        = RGBHex(238, 232, 170)
	Palegreen            = RGBHex(152, 251, 152)
	Paleturquoise        = RGBHex(175, 238, 238)
	Palevioletred        = RGBHex(219, 112, 147)
	Papayawhip           = RGBHex(255, 239, 213)
	Peachpuff            = RGBHex(255, 218, 185)
	Peru                 = RGBHex(205, 133, 63)
	Pink                 = RGBHex(255, 192, 203)
	Plum                 = RGBHex(221, 160, 221)
	Powderblue           = RGBHex(176, 224, 230)
	Purple               = RGBHex(128, 0, 128)
	Rebeccapurple        = RGBHex(102, 51, 153)
	Red                  = RGBHex(255, 0, 0)
	Rosybrown            = RGBHex(188, 143, 143)
	Royalblue            = RGBHex(65, 105, 225)
	Saddlebrown          = RGBHex(139, 69, 19)
	Salmon               = RGBHex(250, 128, 114)
	Sandybrown           = RGBHex(244, 164, 96)
	Seagreen             = RGBHex(46, 139, 87)
	Seashell             = RGBHex(255, 245, 238)
	Sienna               = RGBHex(160, 82, 45)
	Silver               = RGBHex(192, 192, 192)
	Skyblue              = RGBHex(135, 206, 235)
	Slateblue            = RGBHex(106, 90, 205)
	Slategray            = RGBHex(112, 128, 144)
	Slategrey            = RGBHex(112, 128, 144)
	Snow                 = RGBHex(255, 250, 250)
	Springgreen          = RGBHex(0, 255, 127)
	Steelblue            = RGBHex(70, 130, 180)
	Tan                  = RGBHex(210, 180, 140)
	Teal                 = RGBHex(0, 128, 128)
	Thistle              = RGBHex(216, 191, 216)
	Tomato               = RGBHex(255, 99, 71)
	Turquoise            = RGBHex(64, 224, 208)
	Violet               = RGBHex(238, 130, 238)
	Wheat                = RGBHex(245, 222, 179)
	White                = RGBHex(255, 255, 255)
	Whitesmoke           = RGBHex(245, 245, 245)
	Yellow               = RGBHex(255, 255, 0)
	Yellowgreen          = RGBHex(154, 205, 50)
)

Named color values

Functions

This section is empty.

Types

type Color

type Color struct {
	R float64
	G float64
	B float64
	A float64
}

Color holds rgba values for a color.

func CMYK

func CMYK(c, m, y, k float64) Color

CMYK creates a color struct using cyan, yellow, magenta and black.

func FromCSSString added in v0.8.5

func FromCSSString(str string) Color

FromCSSString creates a new Color struct from a string like #rrggbb.

func Grey

func Grey(shade float64) Color

Grey creates a new Color struct with rgb all equal to the same value from 0.0 to 1.0 (a = 1.0).

func GreyHex

func GreyHex(shade int) Color

GreyHex creates a new Color struct with rgb all equal to the same value from 0 to 255 (a = 1.0).

func HSL

func HSL(h, s, l float64) Color

HSL creates a Color struct using hue (0.0 - 360.0), value (0.0 - 1.0) and lightness (0.0 - 1.0)

func HSLA

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

HSLA creates a Color struct using hue (0.0 - 360.0), value (0.0 - 1.0), lightness (0.0 - 1.0), and alpha (0.0 - 1.0)

func HSV

func HSV(h float64, s float64, v float64) Color

HSV creates a Color struct using hue (0.0 - 360.0), value (0.0 - 1.0) and value (0.0 - 1.0) (a = 1.0).

func HSVA

func HSVA(h float64, s float64, v float64, a float64) Color

HSVA creates a Color struct using hue (0.0 - 360.0), value (0.0 - 1.0), value (0.0 - 1.0) and alpha (0.0 - 1.0).

func Lerp

func Lerp(colorA, colorB Color, t float64) Color

Lerp creates a new color by interpolating between two other colors

func Number

func Number(value int) Color

Number creates a new Color struct with a 24-bit int 0xRRGGBB (a = 1.0).

func NumberWithAlpha

func NumberWithAlpha(value int) Color

NumberWithAlpha creates a new Color struct with a 32-bit int 0xAARRGGBB.

func RGB

func RGB(r float64, g float64, b float64) Color

RGB creates a new Color struct with rgb values from 0.0 to 1.0 each (a = 1.0).

func RGBA

func RGBA(r float64, g float64, b float64, a float64) Color

RGBA creates a new Color struct with rgba values from 0.0 to 1.0 each.

func RGBAHex

func RGBAHex(r int, g int, b int, a int) Color

RGBAHex creates a Color struct with rgba values from 0 to 255 each.

func RGBHex

func RGBHex(r int, g int, b int) Color

RGBHex creates a Color struct with rgb values from 0 to 255 (a = 255).

func RandomGrey

func RandomGrey() Color

RandomGrey creates a Color struct with a random grey shade from 0.0 to 1.0 (a = 1.0).

func RandomGreyRange

func RandomGreyRange(minVal float64, maxVal float64) Color

RandomGreyRange creates a Color struct with a random grey shade from min to max (a = 1.0).

func RandomHue added in v0.8.3

func RandomHue() Color

RandomHue creates a color with a random hue, full saturation and value.

func RandomRGB

func RandomRGB() Color

RandomRGB creates a color struct with random rgb values (a = 1.0).

func (Color) AddColor

func (c Color) AddColor(b Color) Color

AddColor adds a Color to this Color, returning a new Color.

func (Color) AddRGB

func (c Color) AddRGB(r, g, b float64) Color

AddRGB adds a value to each channel, returning a new Color.

func (Color) CSSString added in v0.8.5

func (c Color) CSSString() string

CSSString ...

func (Color) ColorDiff

func (c Color) ColorDiff(colorB Color) float64

ColorDiff returns the euclidian distance between two colors.

func (Color) ColorDiffPercept

func (c Color) ColorDiffPercept(colorB Color) float64

ColorDiffPercept returns the euclidian distance between two colors.

func (Color) Contrast

func (c Color) Contrast(c2 Color) float64

Contrast returns the contrast between this color and another color. ref: https://www.w3.org/TR/2012/NOTE-WCAG20-TECHS-20120103/G17.html

func (Color) Equals

func (c Color) Equals(colorB Color) bool

Equals returns whether or not this color is equal to another channel. Converts each channel to int 0-255 because that's what's actually going to be displayed.

func (Color) Invert

func (c Color) Invert() Color

Invert returns a color with the inverted RGB values of the original.

func (Color) Luminance

func (c Color) Luminance() float64

Luminance returnss the Luminance of a given color

func (Color) Quant

func (c Color) Quant(quant int) Color

Quant quantizes each color channel into a specified number of bands.

func (Color) Rotate

func (c Color) Rotate(degrees float64) Color

Rotate returns a color with the hue rotated by the specified amount.

func (Color) Scale

func (c Color) Scale(mult float64) Color

Scale scales the r, g, b channels by a percent. This will lighten or darken the color. Scale(1.05) will lighten the color by 5% of its current value. Scale(0.95) will darken the color by 5% of its current value. This is virtually the same as getting h, s, l and scaling the l But probably simpler in most cases.

func (Color) ToCMYK

func (c Color) ToCMYK() (float64, float64, float64, float64)

ToCMYK returns the cyan, magenta, yellow and black of a color.

func (Color) ToGray

func (c Color) ToGray() Color

ToGray returns a new grayscale color from this color.

func (Color) ToHSL

func (c Color) ToHSL() (float64, float64, float64)

ToHSL returns the hue, saturation and lightness of a color. hue = 0-360, s = 0-1, l = 0-1

func (Color) ToHSV

func (c Color) ToHSV() (float64, float64, float64)

ToHSV returns the hue, saturation and value of a color. hue = 0-360, s = 0-1, v = 0-1

func (Color) WithSat added in v0.9.0

func (c Color) WithSat(sat float64) Color

WithSat returns a new color with the same hue and value, and the specified saturation.

func (Color) WithVal added in v0.9.0

func (c Color) WithVal(val float64) Color

WithVal returns a new color with the same hue and saturation, and the specified value.

type Palette

type Palette []Color

Palette is a list of colors.

func AchromaticPalette added in v0.8.3

func AchromaticPalette(n int) Palette

AchromaticPalette creates a grayscale palette of n values.

func AchromaticRangePalette added in v0.9.0

func AchromaticRangePalette(minVal, maxVal float64, n int) Palette

AchromaticRangePalette creates a grayscale palette of n values in the given range.

func AnalagousPalette added in v0.8.3

func AnalagousPalette(c Color) Palette

AnalagousPalette creates a palette of the given color and two neighbors.

func ComplementaryPalette added in v0.8.3

func ComplementaryPalette(c Color) Palette

ComplementaryPalette creates a palette of the given color and its complement.

func MonoPalette added in v0.8.3

func MonoPalette(hue float64, n int) Palette

MonoPalette creates a monochrom palette based on the given hue with a range of sat and luminance.

func NewPalette

func NewPalette() Palette

NewPalette creates a new palette of the given size

func PaletteFromCSS added in v0.8.5

func PaletteFromCSS(colors ...string) Palette

PaletteFromCSS creates a new palette with the given css colors in the #rrggbb format.

func PastelPalette added in v0.8.3

func PastelPalette(hue0, hue1 float64, n int) Palette

PastelPalette creates a light pastel palette interpolated between the two hues.

func ReadPalette added in v0.8.4

func ReadPalette(path string) Palette

ReadPalette loads a serialized palette from disk.

func RectangularPalette added in v0.8.3

func RectangularPalette(c Color) Palette

RectangularPalette creates a four color rectangular palette based on the given color.

func SequentialPalette added in v0.8.3

func SequentialPalette(colA, colB Color, n int) Palette

SequentialPalette creates a palette of n colors interpolated between the two given colors.

func SpectralPalette added in v0.8.3

func SpectralPalette(hue0, hue1 float64, n int) Palette

SpectralPalette creates a palette of n colors interpolated between the two hues.

func SplitCompPalette added in v0.8.3

func SplitCompPalette(c Color) Palette

SplitCompPalette creates a palette with the given color and its two split complements.

func TetradicPalette added in v0.8.3

func TetradicPalette(c Color) Palette

TetradicPalette creates a palette with four colors in a square formation based on the given color.

func TriadicPalette added in v0.8.3

func TriadicPalette(c Color) Palette

TriadicPalette creates a tetradic paletted based on the given color.

func (*Palette) Add

func (p *Palette) Add(color Color)

Add adds a color to the palette.

func (*Palette) AddRGB

func (p *Palette) AddRGB(r, g, b float64)

AddRGB adds a new color defined by the rgb channels.

func (*Palette) AddRGBA

func (p *Palette) AddRGBA(r, g, b, a float64)

AddRGBA adds a new color defined by the rgb channels.

func (Palette) Equal added in v0.8.5

func (p Palette) Equal(pal Palette) bool

Equal reports whether or not this palette is equal to another.

func (*Palette) Filter added in v0.8.9

func (p *Palette) Filter(filter func(Color) bool)

Filter removes any colors in the filter which do not pass the given function. Reduces the size of the palette.

func (*Palette) FilterDark added in v0.8.9

func (p *Palette) FilterDark(minValue float64)

FilterDark filters out any colors whose values are less than the given minimum value. Reduces the size of the palette.

func (Palette) Get

func (p Palette) Get(index int) Color

Get returns the color at the given index, if available.

func (Palette) GetRandom

func (p Palette) GetRandom() Color

GetRandom returns a random color from the palette.

func (Palette) GetWeightedRandom added in v0.9.0

func (p Palette) GetWeightedRandom(weights ...float64) Color

GetWeightedRandom returns a random color from the palette.

func (Palette) Len

func (p Palette) Len() int

Len returns the size of the palette (used for sorting).

func (Palette) Less

func (p Palette) Less(i, j int) bool

Less returns if one color has lower luminance another (used for sorting).

func (Palette) RandomHueRotate added in v0.9.0

func (p Palette) RandomHueRotate(amt float64)

RandomHueRotate randomly rotates the hue of all colors in this palette.

func (Palette) RandomizeSat added in v0.9.0

func (p Palette) RandomizeSat(minSat, maxSat float64)

RandomizeSat randomizes the saturation of all colors in this palette to be in the specified range.

func (Palette) RandomizeValue added in v0.9.0

func (p Palette) RandomizeValue(minVal, maxVal float64)

RandomizeValue randomizes the value of all colors in this palette to be in the specified range.

func (*Palette) Remove added in v0.8.4

func (p *Palette) Remove(index int)

Remove removes the color at the given index

func (Palette) Reverse

func (p Palette) Reverse()

Reverse reverses the order of the colors in the palette.

func (Palette) Save added in v0.8.4

func (p Palette) Save(path string)

Save serializes and saves a palette to disk.

func (Palette) SetSaturation added in v0.9.0

func (p Palette) SetSaturation(sat float64)

SetSaturation sets the saturation of all colors in this palette to the specified saturation.

func (Palette) SetValue added in v0.9.0

func (p Palette) SetValue(val float64)

SetValue sets the value of all colors in this palette to the specified value.

func (Palette) Size

func (p Palette) Size() int

Size returns the number of colors in this palette.

func (Palette) SortByHue

func (p Palette) SortByHue(offset float64)

SortByHue sorts the palette colors based on their hue.

func (Palette) SortByVal added in v0.8.9

func (p Palette) SortByVal()

Sort sorts the palette based on luminance

func (Palette) Swap

func (p Palette) Swap(i, j int)

Swap swaps two colors in the palette (used for sorting).

func (*Palette) Unique added in v0.9.0

func (p *Palette) Unique()

Unique removes any duplicate colors from the palette.

Jump to

Keyboard shortcuts

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