Constructor signature is simply 4 optional parameters, (red, green, blue, alpha).
The default colour e.g. new Color(); will give you a color of rgba(0,0,0,1) or black.
The red,green,blue values range from 0-255. The alpha value ranges from 0-1. Mimicking the CSS rgba syntax.
Optionally the Color class has several static member to create a Color class from different sources.
Color.fromString(string)
Acceptable string formats are:
A 3 digit hex string. e.g: "#000"
A 6 digit hex string. e.g: "#000000"
The CSS rgb(red,green,blue) format
The CSS rgba(red,green,blue,alpha) format.
Several "english" color words, which can be found inside the ColorCode.ts's ColorMap. Note that the ColorMap is not exposed to the public API (But ColorCode is).
Color.fromHex(hex: ColorCode | number)
To support usages such as:
var color: Color = Color.fromHex(0xFFFFFF);
Note that a hex literal is ultimately just a number object, so any integer would work, but using hex notation will make it a bit easier to understand what color it is. Or even better, use the ColorCode object directly.
var color: Color = Color.fromHex(ColorCode.WHITE);
Color.fromColorCode(code: ColorCode)
This is essentially an alias to Color.fromHex, but an API name to make it more clear what is going into the Color class.
New objects in jiggy/util package
The color class provides a flexible API.
Constructor signature is simply 4 optional parameters,
(red, green, blue, alpha)
. The default colour e.g.new Color();
will give you a color of rgba(0,0,0,1) or black.The red,green,blue values range from 0-255. The alpha value ranges from 0-1. Mimicking the CSS rgba syntax.
Optionally the Color class has several static member to create a Color class from different sources.
Color.fromString(string)
Acceptable string formats are:
Color.fromHex(hex: ColorCode | number)
To support usages such as:
Note that a hex literal is ultimately just a number object, so any integer would work, but using hex notation will make it a bit easier to understand what color it is. Or even better, use the ColorCode object directly.
Color.fromColorCode(code: ColorCode)
This is essentially an alias to Color.fromHex, but an API name to make it more clear what is going into the Color class.