Documentation ¶
Index ¶
- Constants
- func ContrastRatio(a, b RGBA) float32
- func MulAlpha(c color.NRGBA, alpha uint8) color.NRGBA
- type HSLA
- type RGBA
- func (rgba RGBA) Array() [4]float32
- func (col RGBA) Darken(p float32) RGBA
- func (col RGBA) Emphasize(p float32) RGBA
- func (col RGBA) Float32() (r, g, b, a float32)
- func (col RGBA) HSLA() HSLA
- func (col RGBA) IsBright() bool
- func (col RGBA) IsBrightAlt() bool
- func (col RGBA) Lighten(p float32) RGBA
- func (col RGBA) Luminance() float32
- func (col RGBA) Opaque() RGBA
- func (col RGBA) PerceivedLightness() float32
- func (col RGBA) SRGB() color.NRGBA
Constants ¶
const ( // All legible text should have at least this contrast ratio. MinimumContrastRatio = 4.5 / 1.0 // With the exception of large text, which can have lower contrast ratio. LargeTextMinimumContrastRatio = 3.0 / 1.0 // Enhanced Contrast mode has stricter values. EnhancedMinimumContrastRatio = 7 / 1.0 EnhancedLargeTextMinimumContrastRatio = 4.5 / 1.0 // DefaultBlend is good argument for Emphasis, Lighten and Darken. DefaultBlend = 0.15 )
Constants defined by https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast
Variables ¶
This section is empty.
Functions ¶
func ContrastRatio ¶
ContrastRatio calculates contrast ratio between two values. Returns a value between 0 and 21.
See https://www.w3.org/TR/WCAG20/#contrast-ratiodef for more details.
Types ¶
type HSLA ¶
type HSLA struct{ H, S, L, A float32 }
HSLA is a 32 bit floating point HSL space color, all from 0 to 1.
func (HSLA) Darken ¶
Darken returns linear color blend with black in HSL colorspace with the specified percentage.
func (HSLA) IsBright ¶
IsBright estimates whether the color is considered as bright or not based on CIELab perceived lightness.
type RGBA ¶
type RGBA struct {
R, G, B, A float32
}
RGBA is a 32 bit floating point linear space color.
func LinearFromSRGB ¶
LinearFromSRGB converts from SRGBA to RGBA.
func (RGBA) Darken ¶
DarkenRGB returns linear color blend with black in RGB colorspace with the specified percentage. Returns `(r,g,b) * (1 - p) + (0, 0, 0) * p`.
func (RGBA) IsBright ¶
IsBright estimates whether the color is considered as bright or not based on CIELab perceived lightness.
func (RGBA) IsBrightAlt ¶
IsBrightAlt determines whether color is bright based on whether contrast ratio to white or black is higher.
func (RGBA) Lighten ¶
LightenRGB returns linear color blend with white in RGB colorspace with the specified percentage. Returns `(r,g,b) * (1 - p) + (1, 1, 1) * p`.
func (RGBA) Luminance ¶
Luminance calculates the relative luminance of a linear RGBA color. Normalized to 0 for black and 1 for white.
See https://www.w3.org/TR/WCAG20/#relativeluminancedef for more details.
func (RGBA) PerceivedLightness ¶
PerceivedLightness calculates the perceived lightness from 0 black to 100 white. 50 is the middle gray.
This corresponds to the L value in CIELab color space. It does not take into account some psychophyscal attributes like Helmholtz-Kohlrausch effect.