Yinteger / Jiggy.io

GNU General Public License v3.0
1 stars 1 forks source link

Color class #24

Closed breautek closed 6 years ago

breautek commented 6 years ago

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:

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.