type

Color

src @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 saturate(-percentage).

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 a is zero, fully transparent

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 opacity is between 0.0 and 1.0.

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 "#RRGGBB" hex string, otherwise format as "rbga()" notation.

Slot Details

a

src const Float a

The alpha component from 0.0 to 1.0

asColorPaint

src virtual override Color asColorPaint()

Return this

b

src Int b()

The blue component from 0 to 255.

black

src const static Color black := Color.make(0, 1.0)

Black is #000

darker

src Color darker(Float percentage := 0.2f)

Get a color which is a dark shade of this color. This decreases the brightness by the given percentage which is a float between 0.0 and 1.0.

desaturate

src Color desaturate(Float percentage := 0.2f)

Convenience for saturate(-percentage).

equals

src virtual override Bool equals(Obj? that)

Equality

fromStr

src 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

src Int g()

The green component from 0 to 255.

h

src Float h()

Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, s, l.

hash

src virtual override Int hash()

Return the hash code.

interpolateHsl

src static Color interpolateHsl(Color a, Color b, Float t)

Interpolate between a and b where t is 0.0 to 1.0 using HSL color model.

interpolateRgb

src static Color interpolateRgb(Color a, Color b, Float t)

Interpolate between a and b where t is 0.0 to 1.0 using RGB color model.

isColorPaint

src virtual override Bool isColorPaint()

Always return true

isTransparent

src Bool isTransparent()

Return if a is zero, fully transparent

l

src Float l()

Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, s.

lighter

src Color lighter(Float percentage := 0.2f)

Get a color which is a lighter shade of this color. This increases the brightness by the given percentage which is a float between 0.0 and 1.0.

make

src new make(Int rgb := 0, Float a := 1.0f)

Make a new instance with the RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue. Alpha should be a float between 1.0 and 0.0.

makeHsl

src static Color makeHsl(Float h, Float s, Float l, Float a := 1.0f)

Construct a color using HSL model (hue, saturation, lightness):

  • hue as 0.0 to 360.0
  • saturation as 0.0 to 1.0
  • lightness (or brightness) as 0.0 to 1.0
  • alpha as 0.0 to 1.0 Also see h, s, l.

makeRgb

src static Color makeRgb(Int r, Int g, Int b, Float a := 1.0f)

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

src Color opacity(Float opacity := 1.0f)

Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0.

r

src Int r()

The red component from 0 to 255.

rgb

src const Int rgb

The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.

s

src Float s()

Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, l.

saturate

src Color saturate(Float percentage := 0.2f)

Adjust saturation as percentage between -1..1.

toHexStr

src Str toHexStr()

Format as #RGB, #RRGGBB or #RRGGBBAA syntax

toStr

src virtual override Str toStr()

If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.

transparent

src const static Color transparent := Color.make(0, 0.0)

Transparent constant with opacity set to zero

white

src const static Color white := Color.make(16777215, 1.0)

White is #FFF