- Index
- »
- fan.graphics
- »
- Color
Color
@Js
@Serializable { simple=true }
const class Color : Obj, Paint
Models an CSS4 RGB color with alpha
Parse color from CSS 4 string
Make a new instance with the RGB components masked together
The alpha component from 0.0 to 1.0
White is #FFF
Black is #000
The RGB components masked together
Transparent constant with opacity set to zero
If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation
The blue component from 0 to 255
The green component from 0 to 255
Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness)
Always return true
Get a color which is a lighter shade of this color
Lightness (brightness) as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness)
Return this
Format as #RGB, #RRGGBB or #RRGGBBAA syntax
Interpolate between a and b where t is 0.0 to 1.0 using RGB color model
The red component from 0 to 255
Get a color which is a dark shade of this color
Construct a color using HSL model (hue, saturation, lightness)
Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness)
Adjust saturation as percentage between -1..1
Equality
Return if a is zero, fully transparent
Convenience for saturate(-percentage)
Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0
Return the hash code
Interpolate between a and b where t is 0.0 to 1.0 using HSL color model
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
const Float : a
The alpha component from 0.0 to 1.0
virtual Color asColorPaint()
Return this
Int b()
The blue component from 0 to 255.
const static Color : black
Black is #000
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.
Color desaturate(Float percentage)
Convenience for saturate(-percentage).
virtual Bool equals(Obj? that)
Equality
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%)")
Int g()
The green component from 0 to 255.
Float h()
Hue as a float between 0.0 and 360.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, s, l.
virtual Int hash()
Return the hash code.
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.
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.
virtual Bool isColorPaint()
Always return true
Bool isTransparent()
Return if a is zero, fully transparent
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.
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.
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.
static Color makeHsl(Float h, Float s, Float l, Float a)
Construct a color using HSL model (hue, saturation, lightness):
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.
Color opacity(Float opacity)
Adjust the opacity of this color and return new instance, where opacity is between 0.0 and 1.0.
Int r()
The red component from 0 to 255.
const Int : rgb
The RGB components masked together: bits 16-23 red; bits 8-15 green; bits 0-7 blue.
Float s()
Saturation as a float between 0.0 and 1.0 of the HSL model (hue, saturation, lightness). Also see makeHsl, h, l.
Color saturate(Float percentage)
Adjust saturation as percentage between -1..1.
Str toHexStr()
Format as #RGB, #RRGGBB or #RRGGBBAA syntax
virtual Str toStr()
If the alpha component is 1.0, then format as "#RRGGBB" hex string, otherwise format as "rbga()" notation.
const static Color : transparent
Transparent constant with opacity set to zero
const static Color : white
White is #FFF