type
Color
@Js
@Serializable { simple=true }
const class Color : Obj, Paint
Models an CSS4 RGB color with alpha
constructors
| fromStr |
Parse color from CSS 4 string. |
|---|---|
| make |
Make a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. |
fields
| a |
The alpha component from 0.0 to 1.0 |
|---|---|
| black |
Black is #000 |
| rgb |
The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. |
| transparent |
Transparent constant with opacity set to zero |
| white |
White is #FFF |
methods
| asColorPaint |
Return this |
|---|---|
| b |
The blue component from 0 to 255. |
| darker |
Get a color which is a dark shade of this color. |
| desaturate |
Convenience for |
| equals |
Equality |
| g |
The green component from 0 to 255. |
| h |
Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). |
| hash |
Return the hash code. |
| interpolateHsl |
Interpolate between a and b where t is 0.0 to 1.0 using HSL color model. |
| interpolateRgb |
Interpolate between a and b where t is 0.0 to 1.0 using RGB color model. |
| isColorPaint |
Always return true |
| isTransparent |
Return if |
| l |
Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). |
| lighter |
Get a color which is a lighter shade of this color. |
| makeHsl |
Construct a color using HSL model (hue, saturation, lightness) |
| makeRgb |
Make a new instance with the RGB individual components as integers between 0 and 255 and alpha as float between 1.0 and 0.0. |
| opacity |
Adjust the opacity of this color and return new instance, where |
| r |
The red component from 0 to 255. |
| s |
Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). |
| saturate |
Adjust saturation as percentage between -1..1. |
| toHexStr |
Format as #RGB, #RRGGBB or #RRGGBBAA syntax |
| toStr |
If the alpha component is 1.0, then format as |
Slot Details
a
const Float a
The alpha component from 0.0 to 1.0
asColorPaint
virtual override Color asColorPaint()
Return this
b
Int b()
The blue component from 0 to 255.
black
const static Color black := Color.make(0, 1.0)
Black is #000
darker
desaturate
equals
fromStr
static new fromStr(Str s, Bool checked := true)
Parse color from CSS 4 string. If invalid and checked is true then throw ParseErr otherwise return null. The following formats are supported:
- CSS keyword color
- #RRGGBB
- #RRGGBBAA
- #RGB
- #RGBA
- rgb(r, g b)
- rgba(r, g, b, a)
- hsl(h, s, l)
- hsla(h, s, l, a)
Functional notation works with comma or space separated arguments.
Examples:
Color.fromStr("red")
Color.fromStr("#8A0")
Color.fromStr("#88AA00")
Color.fromStr("rgba(255, 0, 0, 0.3)")
Color.fromStr("rgb(100% 0% 0% 25%)")
g
Int g()
The green component from 0 to 255.
h
hash
virtual override Int hash()
Return the hash code.
interpolateHsl
interpolateRgb
isColorPaint
virtual override Bool isColorPaint()
Always return true
isTransparent
l
lighter
make
makeHsl
makeRgb
opacity
r
Int r()
The red component from 0 to 255.
rgb
const Int rgb
The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.
s
saturate
toHexStr
Str toHexStr()
Format as #RGB, #RRGGBB or #RRGGBBAA syntax
toStr
virtual override Str toStr()
If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.
transparent
const static Color transparent := Color.make(0, 0.0)
Transparent constant with opacity set to zero
white
const static Color white := Color.make(16777215, 1.0)
White is #FFF