class

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

fields a

The alpha component from 0.0 to 1.0

white

White is #FFF

black

Black is #000

rgb

The RGB components masked together

transparent

Transparent constant with opacity set to zero

methods toStr

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

b

The blue component from 0 to 255

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)

isColorPaint

Always return true

lighter

Get a color which is a lighter shade of this color

l

Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness)

asColorPaint

Return this

toHexStr

Format as #RGB, #RRGGBB or #RRGGBBAA syntax

interpolateRgb

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

r

The red component from 0 to 255

darker

Get a color which is a dark shade of this color

makeHsl

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

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

equals

Equality

isTransparent

Return if a is zero, fully transparent

desaturate

Convenience for saturate(-percentage)

opacity

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

hash

Return the hash code

interpolateHsl

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

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

a const Float : a

The alpha component from 0.0 to 1.0

asColorPaint virtual Color asColorPaint()

Return this

b Int b()

The blue component from 0 to 255.

black const static Color : black

Black is #000

darker Color darker(Float percentage)

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)

Convenience for saturate(-percentage).

equals virtual Bool equals(Obj? that)

Equality

fromStr static new fromStr(Str s, Bool checked)

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 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 virtual Int hash()

Return the hash code.

interpolateHsl 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 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 virtual Bool isColorPaint()

Always return true

isTransparent Bool isTransparent()

Return if a is zero, fully transparent

l 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 Color lighter(Float percentage)

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, Float a)

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)

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)

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)

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

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 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 Color saturate(Float percentage)

Adjust saturation as percentage between -1..1.

toHexStr Str toHexStr()

Format as #RGB, #RRGGBB or #RRGGBBAA syntax

toStr virtual 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

Transparent constant with opacity set to zero

white const static Color : white

White is #FFF

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST