color

package
v0.0.0-...-716269e Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Overview

Package color contains types and functions for color management.

A new color type and model for HSL along with functions:

Complement - return the opposite color on the color wheel
Monochrome - create a monochrome palatte for a color
Analogous - returns the analogous (adjacent) colors from the color wheel
Triad - returns the other two colors in the color wheel triad
Tetrad - returns the other three colors in the color wheel tetrad
Warmer - moves a color towards red by 10%
Cooler - moves a color towards cyan by 10%
Tint - adds 10% of white to a color
Shade - adds 10% of black to a color
Boost - increases saturation by 10%
Tone - adds 10% of gray to a color
Compound - returns the analogous colors of the color's complement

An embedded list of popular color names and their colors, from here - https://github.com/meodai/color-names.

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = color.RGBA{0x00, 0x00, 0x00, 0xff}
	Red     = color.RGBA{0xff, 0x00, 0x00, 0xff}
	Green   = color.RGBA{0x00, 0xff, 0x00, 0xff}
	Blue    = color.RGBA{0x00, 0x00, 0xff, 0xff}
	Yellow  = color.RGBA{0xff, 0xff, 0x00, 0xff}
	Magenta = color.RGBA{0xff, 0x00, 0xff, 0xff}
	Cyan    = color.RGBA{0x00, 0xff, 0xff, 0xff}
	White   = color.RGBA{0xff, 0xff, 0xff, 0xff}

	DarkGray  = color.RGBA{0x63, 0x66, 0x6a, 0xff}
	Gray      = color.RGBA{0x7f, 0x7f, 0x7f, 0xff}
	LightGray = color.RGBA{0xd9, 0xd9, 0xd6, 0xff}

	Brown  = color.RGBA{0xa4, 0x75, 0x51, 0xff}
	Orange = color.RGBA{0xff, 0xa5, 0x00, 0xff}
	Purple = color.RGBA{0x40, 0x00, 0x80, 0xff}

	GopherBlue  = color.RGBA{0x9d, 0xe8, 0xfd, 0xff}
	GopherBrown = color.RGBA{0xf3, 0xe2, 0xc9, 0xff}
	GopherGray  = color.RGBA{0xbd, 0xb9, 0xaf, 0xff}

	StandardPalette = []color.Color{
		Black,
		Red,
		Orange,
		Brown,
		Yellow,
		Green,
		Blue,
		Cyan,
		Purple,
		Magenta,
		White,
		Gray,
	}
)

Predefined colors.

View Source
var BestNamedRGBs []*NamedRGB

NamedRGBs is the slice of colors loaded from the color names file.

View Source
var CSSNamedRGBs []*NamedRGB
View Source
var HSLModel color.Model = color.ModelFunc(hslModel)

HSLModel standard HSL color type with all values in range [0,1]

Functions

func ColorFile0

func ColorFile0() []byte

ColorFile returns a []byte of the color csv file,

func ColorFile1

func ColorFile1() []byte

ColorFile returns a []byte of the color csv file,

func ColorRGBALerp

func ColorRGBALerp(t float64, start, end color.Color) color.RGBA

ColorRGBALerp calculates the color value at t [0,1] given a start and end color in RGB space.

func HuePalette

func HuePalette(hoffs, s, l float64, n int) []color.Color

HuePalette creates a palette n long of equally spaced hues starting from hoffs, using the supplied saturation and lightness.

func NamedRGBPalette

func NamedRGBPalette() []color.Color

NamedRGBPalette performs a concrete to interface conversion

func Random

func Random() color.RGBA

Random returns a randomized color in R, G and B. Alpha is set to 0xff.

func RandomFromPalette

func RandomFromPalette(palette []color.Color) color.Color

RandomFromPalette selects a color from the supplied palette.

Types

type HSL

type HSL struct {
	H, S, L, A float64
}

HSL describes a color in Hue Saturation Lightness space. All values are in range [0,1].

func Analogous

func Analogous(col color.Color) []HSL

Analogous returns the color's analogous colors.

func Boost

func Boost(col color.Color) HSL

Boost returns the color shifted away from gray.

func ColorHSLLerp

func ColorHSLLerp(t float64, start, end color.Color) HSL

ColorHSLLerp calculates the color value at t [0,1] given a start and end color in HSL space.

func ColorHSLLerpS

func ColorHSLLerpS(t float64, start, end color.Color) HSL

ColorHSLLerpS calculates the color value at t [0,1] given a start and end color in HSL space. Differs from ColorHSLLerp in that the shortest path for hue is taken.

func Complement

func Complement(col color.Color) HSL

Complement returns the color's complement.

func Compound

func Compound(col color.Color) []HSL

Compound returns the colors analogous to the color's complement.

func Cooler

func Cooler(col color.Color) HSL

Cooler returns the color shifted toward cyan.

func HuePair

func HuePair(col color.Color, d float64) []HSL

HuePair returns a pair of colors d away on either side of the color. d is in range [0,1]

func LightPair

func LightPair(col color.Color, d float64) []HSL

LightPair returns a pair of colors d away on either side of the color. d is in range [0,1]

func Monochrome

func Monochrome(col color.Color, n int) []HSL

Monochrome returns the color's monochrome palette (excluding black and white). Note the palette may not contain the original color since the values are equally spaced over L.

func NewHSL

func NewHSL(col color.Color) HSL

NewHSL returns the color as an HSL triplet.

func RandomHue

func RandomHue() HSL

RandomHue returns an HSL color with a random hue, fully saturated and 50% lightness.

func SatPair

func SatPair(col color.Color, d float64) []HSL

SatPair returns a pair of colors d away on either side of the color. d is in range [0,1]

func Shade

func Shade(col color.Color) HSL

Shade returns the color shifted towards black.

func Tetrad

func Tetrad(col color.Color) []HSL

Tetrad returns the color's other three tetradics.

func Tint

func Tint(col color.Color) HSL

Tint returns the color shifted towards white.

func Tone

func Tone(col color.Color) HSL

Tone returns the color shifted towards gray.

func Triad

func Triad(col color.Color) []HSL

Triad returns the color's other two triadics.

func Warmer

func Warmer(col color.Color) HSL

Warmer returns the color shifted towards red.

func (HSL) RGBA

func (c HSL) RGBA() (uint32, uint32, uint32, uint32)

RGBA implements the RGBA function from the color.Color interface.

type NamedRGB

type NamedRGB struct {
	Name  string
	Color color.RGBA
}

NamedRGB contains the name of the color and its RGB color representation.

func ByCSSName

func ByCSSName(name string) (*NamedRGB, error)

ByCSSName returns the color given by the name. If there's no match, error will be set.

func ByName

func ByName(name string) (*NamedRGB, error)

ByName returns the color given by the name. If there's no match, error will be set.

func RandomNamedRGB

func RandomNamedRGB() *NamedRGB

RandomNamedRGB returns a random color from the list of named colors.

func (*NamedRGB) RGBA

func (nc *NamedRGB) RGBA() (uint32, uint32, uint32, uint32)

RGBA implements the color.Color interface.

func (*NamedRGB) String

func (nc *NamedRGB) String() string

String returns a string represntation of NamedRGB.

Jump to

Keyboard shortcuts

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