color

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package color provides tools for defining and generating high-contrast color palettes suitable for QR codes and other visual elements.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPalette = Palette{
	ForeGround: color.RGBA{0x00, 0x00, 0x00, 0xff},
	BackGround: color.RGBA{0xef, 0xef, 0xef, 0xff},
}

DefaultPalette defines the default system colors (black on light gray).

Functions

func IdentifyColor

func IdentifyColor(input color.Color, colors []Color) string

IdentifyColor finds the closest color from a list of Color objects using Euclidean distance.

func Register

func Register(name Name, p Palette)

Register adds a new palette to the registry. This allows external packages to inject new color cases as plugins.

Types

type Color

type Color interface {
	// Name returns the descriptive name of the color.
	Name() string
	// Palette returns the foreground and background RGBA values.
	Palette() (foreground color.RGBA, background color.RGBA)
}

Color defines the behavior for color objects.

func DefaultColors

func DefaultColors() []Color

DefaultColors returns a list of all built-in Color objects currently registered.

type Name

type Name string

Name defines a custom type for palette identification.

const (
	Black   Name = "black"
	White   Name = "white"
	Gray    Name = "gray"
	Blue    Name = "blue"
	Red     Name = "red"
	Green   Name = "green"
	Yellow  Name = "yellow"
	Magenta Name = "magenta"
	Cyan    Name = "cyan"
	Orange  Name = "orange"
	Purple  Name = "purple"
	Gold    Name = "gold"
	Silver  Name = "silver"
	Pink    Name = "pink"
	Brown   Name = "brown"
	Navy    Name = "navy"
	Lime    Name = "lime"
	Teal    Name = "teal"
	Indigo  Name = "indigo"
	Violet  Name = "violet"
	Crimson Name = "crimson"
	Olive   Name = "olive"
	Maroon  Name = "maroon"
	SkyBlue Name = "skyblue"
	Rose    Name = "rose"
	Emerald Name = "emerald"
)

func (Name) Name

func (n Name) Name() string

Name returns the string representation of the color name. This is part of the Color interface implementation.

func (Name) Palette added in v1.2.0

func (n Name) Palette() (foreground color.RGBA, background color.RGBA)

Palette returns the foreground and background RGBA values for the specific color name. This is part of the Color interface implementation.

type Palette

type Palette struct {
	ForeGround color.RGBA
	BackGround color.RGBA
}

Palette groups the foreground and background colors for the palette.

func NewPalette

func NewPalette(name Name) Palette

NewPalette returns a Palette based on a Name. It searches the registry for the name; if not found, it returns the DefaultPalette.

Jump to

Keyboard shortcuts

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