const class graphics::Color

sys::Obj
  graphics::Color : graphics::Paint

@Js
@Serializable { simple=true }

Source

Models an CSS4 RGB color with alpha

a

const Float a

Source

The alpha component from 0.0 to 1.0

asColorPaint

virtual override Color asColorPaint()

Source

Return this

b

Int b()

Source

The blue component from 0 to 255.

black

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

Source

Black is #000

darker

Color darker(Float percentage := 0.2f)

Source

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

Color desaturate(Float percentage := 0.2f)

Source

Convenience for saturate(-percentage).

equals

virtual override Bool equals(Obj? that)

Source

Equality

fromStr

static new fromStr(Str s, Bool checked := true)

Source

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()

Source

The green component from 0 to 255.

h

Float h()

Source

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

hash

virtual override Int hash()

Source

Return the hash code.

interpolateHsl

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

Source

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

interpolateRgb

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

Source

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

isColorPaint

virtual override Bool isColorPaint()

Source

Always return true

isTransparent

Bool isTransparent()

Source

Return if a is zero, fully transparent

l

Float l()

Source

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

lighter

Color lighter(Float percentage := 0.2f)

Source

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

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

Source

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

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

Source

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

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

Source

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

Color opacity(Float opacity := 1.0f)

Source

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

r

Int r()

Source

The red component from 0 to 255.

rgb

const Int rgb

Source

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

s

Float s()

Source

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

saturate

Color saturate(Float percentage := 0.2f)

Source

Adjust saturation as percentage between -1..1.

toHexStr

Str toHexStr()

Source

Format as #RGB, #RRGGBB or #RRGGBBAA syntax

toStr

virtual override Str toStr()

Source

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)

Source

Transparent constant with opacity set to zero

white

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

Source

White is #FFF