Record Class Color
- Record Components:
r- redg- greenb- bluea- alpha (1 = opaque)
- All Implemented Interfaces:
Paint
[0..1].-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionColor(float r, float g, float b, float a) Creates an instance of aColorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloata()Returns the value of thearecord component.floatb()Returns the value of thebrecord component.static Colorcmyk(float cyan, float magenta, float yellow, float key, float alpha) From cyan/magenta/yellow/key, each in [0,1].static doublecontrastRatio(Color a, Color b) WCAG 2.1 contrast ratio between two colours, from 1 (identical) to 21 (black on white).final booleanIndicates whether some other object is "equal to" this one.static ColorParses#RGB,#RGBA,#RRGGBBor#RRGGBBAA, with or without the#.floatg()Returns the value of thegrecord component.final inthashCode()Returns a hash code value for this object.static Colorhsv(float hue, float saturation, float value, float alpha) From hue/saturation/value.floathue()Hue in degrees [0,360).Linear interpolation between this color andotherattin [0..1].doubleCIE L* in [0,100]: perceptual lightness, where a difference of 1 is roughly the smallest step a person can see anywhere on the scale.floatr()Returns the value of therrecord component.doubleWCAG 2.1 relative luminance in [0,1]: the sRGB channels linearized and weighted for the eye's response, so 0 is black and 1 is white.static Colorrgb(int rgb) Opaque color from a0xRRGGBBvalue.static Colorrgba(int rgb, float alpha) Color from a0xRRGGBBvalue plus explicit alpha.floatSaturation in [0,1]: how far from grey.float[]toCmyk(float[] out) Cyan, magenta, yellow and key in [0,1]: the inverse ofcmyk(float, float, float, float, float).toHex()"#RRGGBB", or"#RRGGBBAA"when not fully opaque.final StringtoString()Returns a string representation of this record class.floatvalue()Value in [0,1]: the brightest channel.withAlpha(float alpha)
-
Field Details
-
TRANSPARENT
-
BLACK
-
WHITE
-
-
Constructor Details
-
Method Details
-
rgb
Opaque color from a0xRRGGBBvalue. -
rgba
Color from a0xRRGGBBvalue plus explicit alpha. -
withAlpha
- Returns:
- this color with its alpha replaced by
alpha
-
lerp
Linear interpolation between this color andotherattin [0..1]. -
hsv
From hue/saturation/value.hueis in degrees and wraps, so 370 and -350 both mean 10;saturation,valueandalphaare clamped to [0,1]. -
hue
public float hue()Hue in degrees [0,360). Grey has no hue and answers 0; a picker must keep its own hue across a trip through grey, or dragging saturation to zero would lose which colour you were on. -
saturation
public float saturation()Saturation in [0,1]: how far from grey. -
value
public float value()Value in [0,1]: the brightest channel. -
cmyk
From cyan/magenta/yellow/key, each in [0,1].Naive, not colour-managed. This is the plain arithmetic conversion every colour picker offers, and it is a convenience for people who think in ink percentages, not a substitute for a profile. Print work needs one; this will not match a press.
-
toCmyk
public float[] toCmyk(float[] out) Cyan, magenta, yellow and key in [0,1]: the inverse ofcmyk(float, float, float, float, float). -
toHex
"#RRGGBB", or"#RRGGBBAA"when not fully opaque. -
fromHex
Parses#RGB,#RGBA,#RRGGBBor#RRGGBBAA, with or without the#. Missing alpha is opaque.- Returns:
- the colour, or
nullif the text is not one of those forms: a field being typed into is half-written most of the time, and an exception per keystroke is not a parser, it is a nuisance
-
relativeLuminance
public double relativeLuminance()WCAG 2.1 relative luminance in [0,1]: the sRGB channels linearized and weighted for the eye's response, so 0 is black and 1 is white.Alpha is ignored. A translucent colour has no luminance of its own; what a reader sees is the composite. Composite it over its backdrop first (
backdrop.lerp(this, this.a())) and ask that colour. -
contrastRatio
WCAG 2.1 contrast ratio between two colours, from 1 (identical) to 21 (black on white). Symmetric: which argument is the ink does not change it.The bars the guideline sets: 4.5 for body text, 3 for large text and for meaningful non-text such as an accent-filled indicator or a focus ring, and 7 for the enhanced (AAA) level.
Both colours must be opaque for the answer to mean anything; see
relativeLuminance(). -
lightness
public double lightness()CIE L* in [0,100]: perceptual lightness, where a difference of 1 is roughly the smallest step a person can see anywhere on the scale.This is the scale to measure elevation on. A contrast ratio cannot describe the step from a surface to the card above it in a light palette at all: the step a dark palette reaches at 1.46:1 would need a luminance above 1 to reproduce from a near-white canvas, so the ratio reports two palettes as wildly different when they read identically.
Alpha is ignored, exactly as in
relativeLuminance(). -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
r
public float r()Returns the value of therrecord component.- Returns:
- the value of the
rrecord component
-
g
public float g()Returns the value of thegrecord component.- Returns:
- the value of the
grecord component
-
b
public float b()Returns the value of thebrecord component.- Returns:
- the value of the
brecord component
-
a
public float a()Returns the value of thearecord component.- Returns:
- the value of the
arecord component
-