Documentation ¶
Index ¶
- Constants
- Variables
- func BisectToLimit(y, target_hue float32) mat32.Vec3
- func BisectToSegment(y, target_hue float32) [2]mat32.Vec3
- func Blend(pct float32, x, y color.Color) color.RGBA
- func ContrastColor(c color.Color, ratio float32) color.RGBA
- func ContrastColorTry(c color.Color, ratio float32) (color.RGBA, bool)
- func ContrastRatio(a, b color.Color) float32
- func ContrastRatioOfYs(a, b float32) float32
- func ContrastTone(tone, ratio float32) float32
- func ContrastToneDarker(tone, ratio float32) float32
- func ContrastToneDarkerTry(tone, ratio float32) (float32, bool)
- func ContrastToneLighter(tone, ratio float32) float32
- func ContrastToneLighterTry(tone, ratio float32) (float32, bool)
- func ContrastToneTry(tone, ratio float32) (float32, bool)
- func CriticalPlaneAbove(x float32) int
- func CriticalPlaneBelow(x float32) int
- func Darken(c color.Color, amount float32) color.RGBA
- func Desaturate(c color.Color, amount float32) color.RGBA
- func FindResultByJ(hue_rad, chroma, y float32) *mat32.Vec3
- func GetAxis(v mat32.Vec3, axis int) float32
- func Highlight(c color.Color, amount float32) color.RGBA
- func HueOf(linrgb mat32.Vec3) float32
- func Intercept(source, mid, target float32) float32
- func IsBounded(x float32) bool
- func IsDark(c color.Color) bool
- func IsLight(c color.Color) bool
- func Lighten(c color.Color, amount float32) color.RGBA
- func MatMul(v mat32.Vec3, mat [3][3]float32) mat32.Vec3
- func Midpoint(a, b mat32.Vec3) mat32.Vec3
- func MinHueDistance(a, b float32) float32
- func NthVertex(y float32, n int) mat32.Vec3
- func Samelight(c color.Color, amount float32) color.RGBA
- func Saturate(c color.Color, amount float32) color.RGBA
- func SetCoordinate(source, target mat32.Vec3, coord float32, axis int) mat32.Vec3
- func SolveToRGB(hue, chroma, tone float32) (r, g, b float32)
- func SolveToRGBLin(hue, chroma, tone float32) mat32.Vec3
- func Spin(c color.Color, amount float32) color.RGBA
- func ToneContrastRatio(a, b float32) float32
- func TrueDelinearized(comp float32) float32
- type HCT
- func (h HCT) AsRGBA() color.RGBA
- func (h HCT) RGBA() (r, g, b, a uint32)
- func (h *HCT) SetChroma(chroma float32)
- func (h *HCT) SetColor(ci color.Color)
- func (h *HCT) SetHue(hue float32)
- func (h *HCT) SetToNil()
- func (h *HCT) SetTone(tone float32)
- func (h *HCT) SetUint32(r, g, b, a uint32)
- func (h HCT) String() string
- func (h HCT) WithChroma(chroma float32) HCT
- func (h HCT) WithHue(hue float32) HCT
- func (h HCT) WithTone(tone float32) HCT
Constants ¶
const ( // ContrastAA is the contrast ratio required by WCAG AA for body text ContrastAA float32 = 4.5 // ContrastLargeAA is the contrast ratio required by WCAG AA for large text // (at least 120-150% larger than the body text) ContrastLargeAA float32 = 3 // ContrastGraphicsAA is the contrast ratio required by WCAG AA for graphical objects // and active user interface components like graphs, icons, and form input borders ContrastGraphicsAA float32 = 3 // ContrastAAA is the contrast ratio required by WCAG AAA for body text ContrastAAA float32 = 7 // ContrastLargeAAA is the contrast ratio required by WCAG AAA for large text // (at least 120-150% larger than the body text) ContrastLargeAAA float32 = 4.5 )
Variables ¶
var Model = color.ModelFunc(model)
Model is the standard color.Model that converts colors to HCT.
Functions ¶
func BisectToLimit ¶
func BisectToLimit(y, target_hue float32) mat32.Vec3
Finds a color with the given Y and hue on the boundary of the cube. @param y The Y value of the color. @param target_hue The hue of the color. @return The desired color, in linear RGB coordinates.
func BisectToSegment ¶
func BisectToSegment(y, target_hue float32) [2]mat32.Vec3
Finds the segment containing the desired color. @param y The Y value of the color. @param target_hue The hue of the color. @return A list of two sets of linear RGB coordinates, each corresponding to an endpoint of the segment containing the desired color.
func Blend ¶ added in v0.9.36
Blend returns a color that is the given percent blend between the first and second color; 10 = 10% of the first and 90% of the second, etc; blending is done directly on non-premultiplied HCT values, and a correctly premultiplied color is returned.
func ContrastColor ¶ added in v0.9.36
ContrastColor returns the color that will ensure that the given contrast ratio between the given color and the resulting color is met. If the given ratio can not be achieved with the given color, it returns the color that would result in the highest contrast ratio. The ratio must be between 1 and 21. If the tone of the given color is greater than 50, it tries darker tones first, and otherwise it tries lighter tones first.
func ContrastColorTry ¶ added in v0.9.36
ContrastColorTry returns the color that will ensure that the given contrast ratio between the given color and the resulting color is met. It returns color.RGBA{}, false if the given ratio can not be achieved with the given color. The ratio must be between 1 and 21. If the tone of the given color is greater than 50, it tries darker tones first, and otherwise it tries lighter tones first.
func ContrastRatio ¶ added in v0.9.36
ContrastRatio returns the contrast ratio between the given two colors. The contrast ratio will be between 1 and 21.
func ContrastRatioOfYs ¶ added in v0.9.36
ContrastRatioOfYs returns the contrast ratio of two XYZ Y values.
func ContrastTone ¶ added in v0.9.36
ContrastTone returns the tone that will ensure that the given contrast ratio between the given tone and the resulting tone is met. If the given ratio can not be achieved with the given tone, it returns the tone that would result in the highest contrast ratio. The tone must be between 0 and 100 and the ratio must be between 1 and 21. If the given tone is greater than 50, it tries darker tones first, and otherwise it tries lighter tones first.
func ContrastToneDarker ¶ added in v0.9.36
ContrastToneDarker returns a tone less than or equal to the given tone that ensures that given contrast ratio between the two tones is met. It returns 0 if the given ratio can not be achieved with the given tone. The tone must be between 0 and 100 and the ratio must be between 1 and 21.
func ContrastToneDarkerTry ¶ added in v0.9.36
ContrastToneDarkerTry returns a tone less than or equal to the given tone that ensures that given contrast ratio between the two tones is met. It returns -1, false if the given ratio can not be achieved with the given tone. The tone must be between 0 and 100 and the ratio must be between 1 and 21.
func ContrastToneLighter ¶ added in v0.9.36
ContrastToneLighter returns a tone greater than or equal to the given tone that ensures that given contrast ratio between the two tones is met. It returns 100 if the given ratio can not be achieved with the given tone. The tone must be between 0 and 100 and the ratio must be between 1 and 21.
func ContrastToneLighterTry ¶ added in v0.9.36
ContrastToneLighterTry returns a tone greater than or equal to the given tone that ensures that given contrast ratio between the two tones is met. It returns -1, false if the given ratio can not be achieved with the given tone. The tone must be between 0 and 100 and the ratio must be between 1 and 21.
func ContrastToneTry ¶ added in v0.9.36
ContrastToneTry returns the tone that will ensure that the given contrast ratio between the given tone and the resulting tone is met. It returns -1, false if the given ratio can not be achieved with the given tone. The tone must be between 0 and 100 and the ratio must be between 1 and 21. If the given tone is greater than 50, it tries darker tones first, and otherwise it tries lighter tones first.
func CriticalPlaneAbove ¶
func CriticalPlaneBelow ¶
func Darken ¶
Darken returns a color that is darker by the given absolute HCT tone amount (0-100, ranges enforced)
func Desaturate ¶
Desaturate returns a color that is less saturated by the given absolute HCT chroma amount (0-max that depends on other params but is around 150, ranges enforced)
func FindResultByJ ¶
func FindResultByJ(hue_rad, chroma, y float32) *mat32.Vec3
Finds a color with the given hue, chroma, and Y. @param hue_radians The desired hue in radians. @param chroma The desired chroma. @param y The desired Y. @return The desired color as linear sRGB values.
func GetAxis ¶
GetAxis returns value along axis 0,1,2 -- result is divided by 100 so that resulting numbers are in 0-1 range.
func Highlight ¶
Highlight returns a color that is lighter or darker by the given absolute HCT tone amount (0-100, ranges enforced), making the color darker if it is light (tone >= 50) and lighter otherwise. It is the opposite of Samelight.
func HueOf ¶
func HueOf(linrgb mat32.Vec3) float32
HueOf Returns the hue of a linear RGB color in CAM16.
func Intercept ¶
Solves the lerp equation. @param source The starting number. @param mid The number in the middle. @param target The ending number. @return A number t such that lerp(source, target, t) = mid.
func IsLight ¶
IsLight returns whether the given color is light (has an HCT tone greater than or equal to 50)
func Lighten ¶
Lighten returns a color that is lighter by the given absolute HCT tone amount (0-100, ranges enforced)
func MinHueDistance ¶ added in v0.9.42
MinHueDistance finds the minimum distance between two hues. A positive number means add to a to get to b. A negative number means subtract from a to get to b.
func NthVertex ¶
Returns the nth possible vertex of the polygonal intersection. @param y The Y value of the plane. @param n The zero-based index of the point. 0 <= n <= 11. @return The nth possible vertex of the polygonal intersection of the y plane and the RGB cube, in linear RGB coordinates, if it exists. If this possible vertex lies outside of the cube,
[-1.0, -1.0, -1.0] is returned.
func Samelight ¶
Samelight returns a color that is lighter or darker by the given absolute HCT tone amount (0-100, ranges enforced), making the color lighter if it is light (tone >= 50) and darker otherwise. It is the opposite of Highlight.
func Saturate ¶
Saturate returns a color that is more saturated by the given absolute HCT chroma amount (0-max that depends on other params but is around 150, ranges enforced)
func SetCoordinate ¶
*
- Intersects a segment with a plane. *
- @param source The coordinates of point A.
- @param coordinate The R-, G-, or B-coordinate of the plane.
- @param target The coordinates of point B.
- @param axis The axis the plane is perpendicular with. (0: R, 1: G, 2: B)
- @return The intersection point of the segment AB with the plane R=coordinate,
- G=coordinate, or B=coordinate
func SolveToRGB ¶
SolveToRGB Finds an sRGB (gamma corrected, 0-1 range) color with the given hue, chroma, and tone, if possible. if not possible to represent the target values, the hue and tone will be sufficiently close, and chroma will be maximized.
func SolveToRGBLin ¶
func SolveToRGBLin(hue, chroma, tone float32) mat32.Vec3
SolveToRGBLin Finds an sRGB linear color (represented by mat32.Vec3, 0-100 range) with the given hue, chroma, and tone, if possible. if not possible to represent the target values, the hue and tone will be sufficiently close, and chroma will be maximized.
func Spin ¶
Spin returns a color that has a different hue by the given absolute HCT hue amount (0-360, ranges enforced)
func ToneContrastRatio ¶ added in v0.9.36
ToneContrastRatio returns the contrast ratio between the given two tones. The contrast ratio will be between 1 and 21, and the tones should be between 0 and 100 and will be clamped to such.
func TrueDelinearized ¶
Delinearizes an RGB component, returning a floating-point number. @param rgb_component 0.0 <= rgb_component <= 100.0, represents linear R/G/B channel @return 0.0 <= output <= 255.0, color channel converted to regular RGB space
Types ¶
type HCT ¶
type HCT struct { // hue (h) is the spectral identity of the color (red, green, blue etc) in degrees (0-360) Hue float32 `min:"0" max:"360"` // chroma (C) is the colorfulness or saturation of the color -- greyscale colors have no chroma, and fully saturated ones have high chroma. The maximum varies as a function of hue and tone, but 150 is an upper bound. Chroma float32 `min:"0" max:"150"` // tone is the L* component from the LAB (L*a*b*) color system, which is linear in human perception of lightness. It ranges from 0 to 100. Tone float32 `min:"0" max:"100"` // sRGB standard gamma-corrected 0-1 normalized RGB representation of the color. Critically, components are not premultiplied by alpha. R, G, B, A float32 }
HCT represents a color as hue, chroma, and tone. HCT is a color system that provides a perceptually accurate color measurement system that can also accurately render what colors will appear as in different lighting environments. Directly setting the values of the HCT and RGB fields will have no effect on the underlying color; instead, use the Set methods (HCT.SetHue, etc). The A field (transparency) can be set directly.
func FromColor ¶
FromColor constructs a new HCT color from a standard color.Color
func New ¶
New returns a new HCT representation for given parameters: hue = 0..360 chroma = 0..? depends on other params tone = 0..100 also computes and sets the sRGB normalized, gamma corrected R,G,B values while keeping the sRGB representation within its gamut, which may cause the chroma to decrease until it is inside the gamut.
func SRGBToHCT ¶
SRGBToHCT returns an HCT from given SRGB color coordinates, under standard viewing conditions. The RGB value range is 0-1, and RGB values have gamma correction. Alpha is always 1.
func Uint32ToHCT ¶
Uint32ToHCT returns an HCT from given SRGBA uint32 color coordinates, which are used for interchange among image.Color types. Uses standard viewing conditions, and RGB values already have gamma correction (i.e., they are SRGB values).
func (HCT) RGBA ¶
RGBA implements the color.Color interface. Performs the premultiplication of the RGB components by alpha at this point.
func (*HCT) SetChroma ¶
SetChroma sets the chroma of this color (0 to max that depends on other params), while keeping the sRGB representation within its gamut, which may cause the chroma to decrease until it is inside the gamut.
func (*HCT) SetHue ¶
SetHue sets the hue of this color. Chroma may decrease because chroma has a different maximum for any given hue and tone. 0 <= hue < 360; invalid values are corrected.
func (*HCT) SetTone ¶
SetTone sets the tone of this color (0 < tone < 100), while keeping the sRGB representation within its gamut, which may cause the chroma to decrease until it is inside the gamut.
func (*HCT) SetUint32 ¶
SetUint32 sets components from unsigned 32bit integers (alpha-premultiplied)
func (HCT) WithChroma ¶ added in v0.9.19
WithChroma is like [SetChroma] except it returns a new color instead of setting the existing one.