package color
import "github.com/jphsd/graphics2d/color"
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 ¶
- Variables
- func ColorFile0() []byte
- func ColorFile1() []byte
- func ColorRGBALerp(t float64, start, end color.Color) color.RGBA
- func HuePalette(hoffs, s, l float64, n int) []color.Color
- func NamedRGBPalette() []color.Color
- func Random() color.RGBA
- func RandomFromPalette(palette []color.Color) color.Color
- type Color
- type Gray
- type Gray16
- type HSL
- func Analogous(col color.Color) []HSL
- func Boost(col color.Color) HSL
- func ColorHSLLerp(t float64, start, end color.Color) HSL
- func ColorHSLLerpS(t float64, start, end color.Color) HSL
- func Complement(col color.Color) HSL
- func Compound(col color.Color) []HSL
- func Cooler(col color.Color) HSL
- func HuePair(col color.Color, d float64) []HSL
- func LightPair(col color.Color, d float64) []HSL
- func Monochrome(col color.Color, n int) []HSL
- func NewHSL(col color.Color) HSL
- func RandomHue() HSL
- func SatPair(col color.Color, d float64) []HSL
- func Shade(col color.Color) HSL
- func Tetrad(col color.Color) []HSL
- func Tint(col color.Color) HSL
- func Tone(col color.Color) HSL
- func Triad(col color.Color) []HSL
- func Warmer(col color.Color) HSL
- func (c HSL) RGBA() (uint32, uint32, uint32, uint32)
- type NRGBA
- type NRGBA64
- type NamedRGB
- func ByCSSName(name string) (*NamedRGB, error)
- func ByName(name string) (*NamedRGB, error)
- func RandomNamedRGB() *NamedRGB
- func (nc *NamedRGB) RGBA() (uint32, uint32, uint32, uint32)
- func (nc *NamedRGB) String() string
- type RGBA
- type RGBA64
Variables ¶
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} MidGray = 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, MidGray, } )
Predefined colors.
var BestNamedRGBs []*NamedRGB
NamedRGBs is the slice of colors loaded from the color names file.
var CSSNamedRGBs []*NamedRGB
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 ¶
ColorRGBALerp calculates the color value at t [0,1] given a start and end color in RGB space.
func HuePalette ¶
HuePalette creates a palette n long of equally spaced hues starting from hoffs, using the supplied saturation and lightness.
func NamedRGBPalette ¶
NamedRGBPalette performs a concrete to interface conversion
func Random ¶
Random returns a randomized color in R, G and B. Alpha is set to 0xff.
func RandomFromPalette ¶
RandomFromPalette selects a color from the supplied palette.
Types ¶
type Color ¶
type Gray ¶
type Gray16 ¶
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 ¶
Analogous returns the color's analogous colors.
func Boost ¶
Boost returns the color shifted away from gray.
func ColorHSLLerp ¶
ColorHSLLerp calculates the color value at t [0,1] given a start and end color in HSL space.
func ColorHSLLerpS ¶
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 ¶
Complement returns the color's complement.
func Compound ¶
Compound returns the colors analogous to the color's complement.
func Cooler ¶
Cooler returns the color shifted toward cyan.
func HuePair ¶
HuePair returns a pair of colors d away on either side of the color. d is in range [0,1]
func LightPair ¶
LightPair returns a pair of colors d away on either side of the color. d is in range [0,1]
func Monochrome ¶
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 ¶
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 ¶
SatPair returns a pair of colors d away on either side of the color. d is in range [0,1]
func Shade ¶
Shade returns the color shifted towards black.
func Tetrad ¶
Tetrad returns the color's other three tetradics.
func Tint ¶
Tint returns the color shifted towards white.
func Tone ¶
Tone returns the color shifted towards gray.
func Triad ¶
Triad returns the color's other two triadics.
func Warmer ¶
Warmer returns the color shifted towards red.
func (HSL) RGBA ¶
RGBA implements the RGBA function from the color.Color interface.
type NRGBA ¶
type NRGBA64 ¶
type NamedRGB ¶
NamedRGB contains the name of the color and its RGB color representation.
func ByCSSName ¶
ByCSSName returns the color given by the name. If there's no match, error will be set.
func ByName ¶
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 ¶
RGBA implements the color.Color interface.
func (*NamedRGB) String ¶
String returns a string represntation of NamedRGB.
type RGBA ¶
type RGBA64 ¶
Source Files ¶
aliases.go colors.go doc.go hsl.go lerps.go named.go
- Version
- v0.0.0-20250122000530-812f7f8c78f2 (latest)
- Published
- Jan 22, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 3 weeks ago –
Tools for package owners.