new Color(ropt, gopt, bopt, aopt) → {Color}
Creates a Color Object.
MC uses rbg (0-255) notation with alpha (0-1)
N.B. HTML5 default names colours (e.g. "Aqua" and "Salmon") can be used instead
This:
- {MC.Color}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
r |
Number |
<optional> |
255 | Red Color component (clamped 0-255) |
g |
Number |
<optional> |
255 | Green Color component (clamped 0-255) |
b |
Number |
<optional> |
255 | Blue Color component (clamped 0-255) |
a |
Number |
<optional> |
1 | Color alpha (aka transparency). 1 = solid, 0 = fully transparent |
Returns:
- Type
- Color
Methods
addB(b) → {this}
Adds r to the Color.b
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
b |
Number | value to add the B Color component |
Returns:
Enables method chaining
- Type
- this
addG(g) → {this}
Adds r to the Color.g
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
g |
Number | value to add the G Color component |
Returns:
Enables method chaining
- Type
- this
addR(r) → {this}
Adds r to the Color.r
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
r |
Number | value to add the R Color component |
Returns:
Enables method chaining
- Type
- this
clone() → {MC.Color}
Clones the current Color and returns a NEW copy
Returns:
A NEW color object with the same parameters
- Type
- MC.Color
invert() → {this}
Inverts the Color (i.e. Red value becomes (255 - Red), etc)
This:
- {MC.Color}
Returns:
Enables method chaining
- Type
- this
lerp(Target, Ratio) → {this}
Shifts the color towards a second Color, by the ratio provided
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
Target |
MC.Color | Color to be shifted towards |
Ratio |
Number | ratio of the shift, Values are capped between 0-1 |
Throws:
Console warning if a non-MC.Color is passed in. Color itself is unchanged
N.B Alpha (a) transparency value is also shifted
N.B Alpha (a) transparency value is also shifted
Returns:
Enables method chaining
- Type
- this
minusB(b) → {this}
Subtracts r from the Color.b
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
b |
Number | value to subtract from the B Color component |
Returns:
Enables method chaining
- Type
- this
minusG(g) → {this}
Subtracts r from the Color.g
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
g |
Number | value to subtract from the G Color component |
Returns:
Enables method chaining
- Type
- this
minusR(r) → {this}
Subracts r from the Color.r
Result is clamped between 0 and 255
This:
- {MC.Color}
Parameters:
Name | Type | Description |
---|---|---|
r |
Number | value to subtract from the R Color component |
Returns:
Enables methof chaining
- Type
- this
rgb() → {string}
Returns the RGB value of a {MC.Color} in rbg(r,g,b) format. e.g. "rgb(120,0,255)"
This:
- {MC.Color}
Returns:
- Type
- string
rgba() → {string}
Returns a string of the Color attributes in rbga format e.g. "rgba(120,45,67,0.34)"
Returns:
- Type
- string
set(red_or_Color, greenopt, blueopt, alphaopt) → {this}
Sets a Color
Either a Color can be entered, or (r,g,b,a) (with the a being optional)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
red_or_Color |
Number | MC.Color | Red component (clamped to 0-255) OR the Color to be matched | |
green |
Number |
<optional> |
Green component (clamped to 0-255) |
blue |
Number |
<optional> |
Blue component (clamped to 0-255) |
alpha |
Number |
<optional> |
Transparency (clamped to 0-1) |
Returns:
Enables method chaining
- Type
- this
setA(alpha) → {this}
Sets the Color's Alpha component
N.B although e.g. Color.a = 0.3; could be used, this method clamps the value between valid 0-1
Parameters:
Name | Type | Description |
---|---|---|
alpha |
Number | The new alpha color component |
Returns:
Enables method chaining
- Type
- this
setB(blue) → {this}
Sets the Color's Blue component
N.B although e.g. Color.r = 25; could be used, this method clamps the value between valid 0-255
Parameters:
Name | Type | Description |
---|---|---|
blue |
Number | The new Blue color component |
Returns:
Enables method chaining
- Type
- this
setG(green) → {this}
Sets the Color's Green component
N.B although e.g. Color.g = 25; could be used, this method clamps the value between valid 0-255
Parameters:
Name | Type | Description |
---|---|---|
green |
Number | The new Green color component |
Returns:
Enables method chaining
- Type
- this
setR(red) → {this}
Sets the Color's Red component
N.B although e.g. Color.r = 25; could be used, this method clamps the value between legal 0-255
Parameters:
Name | Type | Description |
---|---|---|
red |
Number | The new Red color component |
Returns:
Enables method chaining
- Type
- this
toGrey() → {this}
Converts the Color to Grayscale
Uses a Luminocity formula of (Red * 0.21 + Green * 0.72 + Blue * 0.07).
See this link for more info (opens in a new window)
N.B both Color.toGray() and Color.toGrey() work
This:
- {MC.Color}
Returns:
Enables method chaining
- Type
- this
toHex() → {string}
Returns the RGB value of a {MC.Color} in hex format. e.g. "#AA05F5"
This:
- {MC.Color}
Returns:
- Type
- string
toSepia() → {this}
This:
- {MC.Color}
Returns:
Enables method chaining
- Type
- this