chroma

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package chroma provides a collection of useful color-related functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyHexCode     = errors.New("hex code must not be empty")
	ErrInvalidHexChar   = errors.New("invalid hexadecimal character")
	ErrInvalidHexFormat = errors.New("invalid hexadecimal format")
)

Functions

func ColorToInt added in v1.1.0

func ColorToInt(c gamut.Color) int

ColorToInt converts a gamut.Color struct into an integer, ignoring the alpha channel. This is a useful shorthand for calling ColorToRgb() and RgbToInt().

func ColorToRgb added in v1.1.0

func ColorToRgb(c gamut.Color) color.RGBA

ColorToRgb converts a gamut.Color struct to a color.RGBA struct, ignoring the alpha channel.

func Default

func Default(defaultRGBA, rgba color.Color, err error) color.Color

Default returns the provided rgba if err == nil, if not it returns the provided defaultRGBA.

func IntToColor added in v1.1.0

func IntToColor(name string, i int) gamut.Color

IntToColor converts an integer to a gamut.Color struct, ignoring the alpha channel and with an optional name. This is a useful shorthand for calling IntToRgb() and RgbToColor().

func IntToRgb added in v1.1.0

func IntToRgb(i int) color.RGBA

IntToRgb converts an integer to a color.RGBA struct, ignoring the alpha channel.

func Must

func Must(rgba color.Color, err error) color.Color

Must returns the provided rgba and panics if err != nil. This is useful for one-line or functions where hex code validity is certain or hard-coded.

func ParseHex

func ParseHex(s string) (color.Color, error)

ParseHex parses a hex code into a color.RGBA struct. The hex code may be in any of the following formats: - #RGB (CSS 3-digit hex color notation) - #RGBA (CSS 3-digit hex color notation + alpha) - #RRGGBB (CSS 6-digit hex color notation) - #RRGGBBA (CSS 6-digit hex color notation + alpha) Thanks to "icza" on StackOverflow for the fast hex code parsing: https://stackoverflow.com/a/54200713

func RgbToColor added in v1.1.0

func RgbToColor(name string, rgb color.RGBA) gamut.Color

RgbToColor converts a color.RGBA struct to a gamut.Color struct, with an optional name.

func RgbToInt added in v1.1.0

func RgbToInt(rgb color.RGBA) int

RgbToInt converts a color.RGBA struct to an integer, ignoring the alpha channel.

Types

type HSLA

type HSLA struct {
	H float64 `json:"h"`
	S float64 `json:"s"`
	L float64 `json:"l"`
	A float64 `json:"a"`
}

func (HSLA) RGBA

func (hsla HSLA) RGBA() (r, g, b, a uint32)

type RGBA

type RGBA struct {
	R float64 `json:"r"`
	G float64 `json:"g"`
	B float64 `json:"b"`
	A float64 `json:"a"`
}

func HSLAtoRGBA

func HSLAtoRGBA(hsla HSLA) (rgba RGBA)

func (RGBA) RGBA

func (rgba RGBA) RGBA() (r, g, b, a uint32)

Jump to

Keyboard shortcuts

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