hsl

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

README

hsl: Hue, Saturation and Lightness

HSL is a standard color model in wide use. HCT produces better psychophysics for actual color perception, but is more computationally expensive.

  • Hue [0..360]
  • Saturation [0..1]
  • Luminance (lightness) [0..1]

HSL vs. HCT Colorspaces

Here is HSL:

hsl colorspace

vs. HCT:

hct colorspace

You can see that HSL has much greater variability in the brightness of the saturated colors, the progression of saturation, and the distribution of hues (yellow / green takes up a large space while red-orange goes by quickly).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Model = color.ModelFunc(model)

Model is the standard color.Model that converts colors to HSL.

Functions

func ContrastColor

func ContrastColor(c color.Color) color.RGBA

ContrastColor returns the color that should be used to contrast this color (white or black), based on the result of IsLight.

func Darken

func Darken(c color.Color, amount float32) color.RGBA

Darken returns a color that is darker by the given absolute HSL lightness amount (0-100, ranges enforced)

func Desaturate

func Desaturate(c color.Color, amount float32) color.RGBA

Desaturate returns a color that is less saturated by the given absolute HSL saturation amount (0-100, ranges enforced)

func HSLtoRGBF32 added in v0.0.7

func HSLtoRGBF32(h, s, l float32) (r, g, b float32)

HSLtoRGBF32 converts HSL values to RGB float32 0..1 values (non alpha-premultiplied) -- based on https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion, https://www.w3.org/TR/css-color-3/ and github.com/lucasb-eyer/go-colorful

func Highlight

func Highlight(c color.Color, amount float32) color.RGBA

Highlight returns a color that is lighter or darker by the given absolute HSL lightness amount (0-100, ranges enforced), making the color darker if it is light (tone >= 0.5) and lighter otherwise. It is the opposite of Samelight.

func HueToRGBF32 added in v0.0.7

func HueToRGBF32(p, q, t float32) float32

func IsDark

func IsDark(c color.Color) bool

IsDark returns whether the given color is dark (has an HSL lightness less than 0.6)

func IsLight

func IsLight(c color.Color) bool

IsLight returns whether the given color is light (has an HSL lightness greater than or equal to 0.6)

func Lighten

func Lighten(c color.Color, amount float32) color.RGBA

Lighten returns a color that is lighter by the given absolute HSL lightness amount (0-100, ranges enforced)

func RGBtoHSLF32 added in v0.0.7

func RGBtoHSLF32(r, g, b float32) (h, s, l float32)

RGBtoHSLF32 converts RGB 0..1 values (non alpha-premultiplied) to HSL -- based on https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion, https://www.w3.org/TR/css-color-3/ and github.com/lucasb-eyer/go-colorful

func Samelight

func Samelight(c color.Color, amount float32) color.RGBA

Samelight returns a color that is lighter or darker by the given absolute HSL lightness amount (0-100, ranges enforced), making the color lighter if it is light (tone >= 0.5) and darker otherwise. It is the opposite of Highlight.

func Saturate

func Saturate(c color.Color, amount float32) color.RGBA

Saturate returns a color that is more saturated by the given absolute HSL saturation amount (0-100, ranges enforced)

func Spin

func Spin(c color.Color, amount float32) color.RGBA

Spin returns a color that has a different hue by the given absolute HSL hue amount (0-360, ranges enforced)

Types

type HSL

type HSL struct {

	// the hue of the color
	H float32 `min:"0" max:"360" step:"5"`

	// the saturation of the color
	S float32 `min:"0" max:"1" step:"0.05"`

	// the luminance (lightness) of the color
	L float32 `min:"0" max:"1" step:"0.05"`

	// the transparency of the color
	A float32 `min:"0" max:"1" step:"0.05"`
}

HSL represents the Hue [0..360], Saturation [0..1], and Luminance (lightness) [0..1] of the color using float32 values In general the Alpha channel is not used for HSL but is maintained so it can be used to fully represent an RGBA color value. When converting to RGBA, alpha multiplies the RGB components.

func FromColor

func FromColor(c color.Color) HSL

FromColor constructs a new HSL color from a standard color.Color

func New

func New(hue, saturation, lightness float32) HSL

New returns a new HSL representation for given parameters: hue = 0..360 saturation = 0..1 lightness = 0..1 A is automatically set to 1

func (HSL) AsRGBA

func (h HSL) AsRGBA() color.RGBA

AsRGBA returns a standard color.RGBA type

func (HSL) RGBA

func (h HSL) RGBA() (r, g, b, a uint32)

Implements the color.Color interface Performs the premultiplication of the RGB components by alpha at this point.

func (*HSL) SetColor

func (h *HSL) SetColor(ci color.Color)

SetColor sets from a standard color.Color

func (*HSL) SetUint32

func (h *HSL) SetUint32(r, g, b, a uint32)

SetUint32 sets components from unsigned 32bit integers (alpha-premultiplied)

func (HSL) String

func (h HSL) String() string

Jump to

Keyboard shortcuts

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