color

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlendColor

func BlendColor(c1, c2 color.Color, weight float64) color.Color

func BlendColors

func BlendColors(hex1 string, hex2 string, count int) ([]string, error)

func Clamp

func Clamp(val, min, max int) int

func ColorDistance

func ColorDistance(r1, g1, b1, r2, g2, b2 uint32) float64

func ColorSimilarityWeight

func ColorSimilarityWeight(c1, c2 color.Color, threshold float64) float64

func ColorsToHex

func ColorsToHex(colors []color.Color) []string

func ConvertHexToFormat

func ConvertHexToFormat(hexColor, format string) (string, string, error)

ConvertHexToFormat converts hex to the specified target format and returns (outputString, outputFormat, error)

func DarkenColor

func DarkenColor(hex string, amount float64) (string, error)

func GenerateAnalogous

func GenerateAnalogous(hex string) ([]string, error)

func GenerateComplementary

func GenerateComplementary(hex string) (string, error)

func GenerateContrast

func GenerateContrast(hex string) (string, error)

func GenerateGradient

func GenerateGradient(hexColors []string, width, height int, angle float64, interpolationMethod string) (image.Image, error)

GenerateGradient creates a gradient image from a list of hex colors. angle: gradient direction in degrees (0=left→right, 90=top→bottom, 180=right→left, 270=bottom→top). hexColors: list of hex color strings (e.g., "#ff0000"). width, height: dimensions of the output image.

func GenerateMonochromatic

func GenerateMonochromatic(hex string, count int) ([]string, error)

func GenerateQuadratic

func GenerateQuadratic(hex string) ([]string, error)

func GenerateShades

func GenerateShades(hex string, count int) ([]string, error)

func GenerateSplitComplementary

func GenerateSplitComplementary(hex string) ([]string, error)

func GenerateTints

func GenerateTints(hex string, count int) ([]string, error)

func GenerateTones

func GenerateTones(hex string, count int) ([]string, error)

func GenerateTriadic

func GenerateTriadic(hex string) ([]string, error)

func GetClrFormat

func GetClrFormat(colorStr string) string

GetClrFormat detects the format of the input color string

func GetClrParseMap

func GetClrParseMap() map[string]func(string) (string, error)

GetClrParseMap returns the map of color format parsers

func HashPalette

func HashPalette(colors []string) string

func HexToRGBA

func HexToRGBA(hexStr string) (color.RGBA, error)

func HexToRGBASlice

func HexToRGBASlice(hexColors []string) ([]color.Color, error)

func HslToHex

func HslToHex(hsl HSL) string

func InvertColor

func InvertColor(clr color.Color) color.Color

func LabToHex

func LabToHex(lab LAB) string

func LightenColor

func LightenColor(hex string, amount float64) (string, error)

func ParseColorToHex

func ParseColorToHex(colorStr string) (string, error)

ParseColorToHex parses any color format and converts it to hex

func ParseHSLToHex

func ParseHSLToHex(colorStr string) (string, error)

ParseHSLToHex parses HSL format and converts to hex

func ParseHexToHex

func ParseHexToHex(colorStr string) (string, error)

ParseHexToHex validates and returns hex color

func ParseLabToHex

func ParseLabToHex(colorStr string) (string, error)

ParseLabToHex parses LAB format and converts to hex

func ParseRGBToHex

func ParseRGBToHex(colorStr string) (string, error)

ParseRGBToHex parses RGB format and converts to hex

func RGBtoHex

func RGBtoHex(c color.RGBA) string

func ToRGBA

func ToRGBA(clrs []color.Color) ([]color.RGBA, error)

------------------- Other methods ---------------------//

func ValidFormats

func ValidFormats() []string

ValidFormats returns the list of valid color formats derived from the parser map

Types

type ColorBox

type ColorBox struct {
	ColorStr string // The original color string (can be any format)
	Box      string // The colored box ANSI code
}

ColorBox represents a colored terminal box with its color value

func CreateColorBox

func CreateColorBox(colorStr string) (ColorBox, error)

CreateColorBox creates a colored box with ANSI codes from any color format

type GradientKeypoint

type GradientKeypoint struct {
	Color    colorful.Color
	Position float64 // Position in range [0,1]
}

GradientKeypoint represents a color at a specific position in the gradient

type GradientTable

type GradientTable []GradientKeypoint

GradientTable contains the keypoints of the gradient

func (GradientTable) GetInterpolatedColorFor

func (gt GradientTable) GetInterpolatedColorFor(t float64, method string) (colorful.Color, error)

GetInterpolatedColorFor returns a HCL-blended color for position t [0,1]

type HSL

type HSL struct {
	H float64 // Hue: 0-360
	S float64 // Saturation: 0-100
	L float64 // Lightness: 0-100
}

HSL represents a color in Hue, Saturation, Lightness color space

func HexToHsl

func HexToHsl(hexStr string) (HSL, error)

type LAB

type LAB struct {
	L float64 // Lightness: 0-100
	A float64 // Green-Red: -128 to 127
	B float64 // Blue-Yellow: -128 to 127
}

LAB represents a color in CIE L*a*b* color space

func HexToLAB

func HexToLAB(hex string) (LAB, error)

type Transformation

type Transformation struct {
	Inputs  []ColorBox
	Outputs []ColorBox
}

Transformation represents input colors -> output colors

func NewTransformation

func NewTransformation(inputs []string, outputs []string) (*Transformation, error)

NewTransformation creates a transformation from input hex colors to output hex colors

func (*Transformation) Print

func (t *Transformation) Print()

Print displays the transformation as: c1 box, c2 box, c3 box -> c4 box, c5 box

func (*Transformation) PrintCompact

func (t *Transformation) PrintCompact()

PrintCompact displays transformation in compact format: inputs -> outputs (no hex labels)

func (*Transformation) PrintCustom

func (t *Transformation) PrintCustom(separator, arrow string)

PrintCustom allows custom formatting with separator and arrow strings

Jump to

Keyboard shortcuts

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