colors

package module
v0.0.0-...-409666d Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 6 Imported by: 0

README

colors

Documentation

Index

Constants

View Source
const XMLNamespaceSVG = "http://www.w3.org/2000/svg"

Variables

View Source
var D65 = Illuminant{
	X: [3]float64{0.4124564, 0.3575761, 0.1804375},
	Y: [3]float64{0.2126729, 0.7151522, 0.0721750},
	Z: [3]float64{0.0193339, 0.1191920, 0.9503041},

	R: [3]float64{3.2406, -1.5372, -0.4986},
	G: [3]float64{-0.9689, 1.8758, 0.0415},
	B: [3]float64{0.0557, -0.2040, 1.0570},
	Reference: XYZ{
		X: 1.05211106084, Y: 1.0, Z: 0.9184170164,
	},
}
View Source
var (
	MonkSkinTone, _ = BuildPalette(
		D65,
		"#f6ede4",
		"#f3e7db",
		"#f7ead0",
		"#eadaba",
		"#d7bd96",
		"#a07e56",
		"#825c43",
		"#604134",
		"#3a312a",
		"#292420",
	)
)

Functions

This section is empty.

Types

type Distance

type Distance func(source Lab, target Lab) float64
var Euclidean Distance = func(source Lab, target Lab) float64 {
	source.L -= target.L
	source.L *= source.L

	source.A -= target.A
	source.A *= source.A

	source.B -= target.B
	source.B *= source.B

	return math.Sqrt(source.L + source.A + source.B)
}

type Gradient

type Gradient struct {
	XMLName   xml.Name `xml:"defs"`
	Gradients []Linear
}

type Illuminant

type Illuminant struct {
	X [3]float64
	Y [3]float64
	Z [3]float64

	R [3]float64
	G [3]float64
	B [3]float64

	Reference XYZ
}

type Lab

type Lab struct {
	L float64
	A float64
	B float64
}

func (Lab) RGB

func (lab Lab) RGB(illuminant Illuminant) RGB

func (Lab) XYZ

func (lab Lab) XYZ(ref XYZ) XYZ

type Linear

type Linear struct {
	XMLName xml.Name `xml:"linearGradient"`
	ID      string   `xml:"id,attr"`
	Stops   []Stop
}

func NewLinear

func NewLinear(id string) Linear

type Palette

type Palette []Lab

func BuildPalette

func BuildPalette(illuminant Illuminant, hs ...string) (Palette, error)

func (Palette) Convert

func (palette Palette) Convert(c color.Color) color.Color

func (Palette) Index

func (palette Palette) Index(c color.Color) int

func (Palette) Match

func (palette Palette) Match(c Lab, d Distance) int

type RGB

type RGB struct {
	R float64
	G float64
	B float64
}

func NewRGB

func NewRGB(c color.Color) RGB

func ParseHex

func ParseHex(s string) (rgb RGB, err error)

func (RGB) Hex

func (rgb RGB) Hex() string

func (RGB) Lab

func (rgb RGB) Lab(illuminant Illuminant) Lab

func (RGB) RGBA

func (rgb RGB) RGBA() (r, g, b, a uint32)

func (RGB) XYZ

func (rgb RGB) XYZ(illuminant Illuminant) XYZ

type Rectangle

type Rectangle struct {
	XMLName xml.Name `xml:"rect"`
	X       int      `xml:"x,attr,omitempty"`
	Y       int      `xml:"y,attr,omitempty"`
	W       uint     `xml:"width,attr"`
	H       uint     `xml:"height,attr"`
	Fill    string   `xml:"fill,attr"`
}

func NewRectangle

func NewRectangle(w, h uint, fill string) Rectangle

type SVG

type SVG struct {
	XMLName   xml.Name `xml:"svg"`
	Namespace string   `xml:"xmlns,attr"`
	W         uint     `xml:"width,attr"`
	H         uint     `xml:"height,attr"`

	Gradient

	Rectangles []Rectangle
}

func NewSVG

func NewSVG(w, h uint) SVG

type Stop

type Stop struct {
	XMLName xml.Name `xml:"stop"`
	Offset  int      `xml:"offset,attr"`
	Color   string   `xml:"stop-color,attr"`
}

func NewStop

func NewStop(offset int, color RGB) Stop

type XYZ

type XYZ struct {
	X float64
	Y float64
	Z float64
}

func (XYZ) Lab

func (xyz XYZ) Lab(ref XYZ) Lab

func (XYZ) RGB

func (xyz XYZ) RGB(illuminant Illuminant) (rgb RGB)

Directories

Path Synopsis
cli
gradient command
swatch command

Jump to

Keyboard shortcuts

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