color

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 4 Imported by: 0

README

color

Color formats implemented in golang (GO)

GoDoc Go report Coverage

Supported formats

RGBA

Red, green, blue, alpha

// Get RGBA values
r, g, b, a := color.RGBA()
// Parse RGBA
color2 := color.Color{255, 255, 255, 255}
HSLA

Hue, saturation, lightness, alpha

⚠ the colors are internally represented as RGBA, so there may be a slight loss in precision if they are converted.

// Get HSLA values
h, s, l, a := color.HSLA()
// Parse HSLA float values (0.0-1.0)
color2 := color.ParseHSLA(1.0, 1.0, 1.0, 1.0)
// Parse HSLA whole numbers values (0-360), (0-100) * 3
color3 := color.ParseHSLAWhole(360, 100, 100, 100)
CMYKA

Cyan, magenta, yellow, black, alpha. Alpha is not often used in situations involving CMYK, but it is available

⚠ the colors are internally represented as RGBA, so there may be a slight loss in precision if they are converted.

// Get CMYKA values
c, m, y, k, a := color.CMYKA()
// Parse CMYKA float values (0-1.0)
color2 := color.ParseCMYKA(1.0, 1.0, 1.0, 0.0)
// Parse CMYKA whole values (0-100)
color3 := color.ParseCMYKAWhole(100, 100, 100, 0)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidColor = errors.New("invalid color")
)

Functions

This section is empty.

Types

type Color

type Color struct {
	Red, Green, Blue, Alpha uint8
}

Color represents a color with 8 bits allocated to each of red, green, blue, alpha

func ParseCMYKA

func ParseCMYKA(c, m, y, k, a float64) (color Color)

func ParseCMYKAWhole

func ParseCMYKAWhole(c, m, y, k, a uint8) Color

func ParseHSLA

func ParseHSLA(h, s, l, a float64) (color Color)

ParseHSLA

func ParseHSLAWhole

func ParseHSLAWhole(h uint16, s, l, a uint8) Color

ParseHSLAWhole parses whole numbers instead of doubles representing the h, s, l, a values. h (0-360), s (0-100), l (0-100), a (0-100)

func ParseInt64 added in v0.1.0

func ParseInt64(i int64) (Color, error)

ParseInt64 converts an int64 into a color. For example, 0xffffff

func ParseString

func ParseString(s string) (Color, error)

ParseString parses a hex color. Supports the formats #000000, #00000000 (with alpha)

func (*Color) CMYKA

func (color *Color) CMYKA() (c, m, y, k, a float64)

CMYKA returns the cyan, magenta, yellow, black, and alpha values of the color

func (*Color) CMYKAWhole

func (color *Color) CMYKAWhole() (c, m, y, k, a uint8)

func (Color) Equal

func (color Color) Equal(c Color) bool

Equal checks the equality of the red, green, blue and alpha channels.

func (*Color) HSLA

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

HSLA converts a color to its hue, saturation, lightness and alpha parts. h (0.0-360.0), s (0.0-1.0), l (0.0-1.0), a (0.0-1.0)

func (*Color) HSLAWhole

func (color *Color) HSLAWhole() (h uint16, s, l, a uint8)

HSLAPercent returns the HSLA values of the color in whole numbers.

func (*Color) MarshalJSON

func (color *Color) MarshalJSON() ([]byte, error)

func (*Color) MarshalText added in v0.1.0

func (color *Color) MarshalText() ([]byte, error)

func (*Color) RGBA

func (color *Color) RGBA() (r, g, b, a uint8)

func (Color) String

func (color Color) String() string

func (*Color) UnmarshalJSON

func (color *Color) UnmarshalJSON(b []byte) (err error)

func (*Color) UnmarshalText added in v0.1.0

func (color *Color) UnmarshalText(d []byte) (err error)

Jump to

Keyboard shortcuts

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