Class: Color

MC.Color(ropt, gopt, bopt, aopt) → {Color}

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:
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
Source:
Returns:
Type
Color

Methods

addB(b) → {this}


Adds r to the Color.b
Result is clamped between 0 and 255
This:
Parameters:
Name Type Description
b Number value to add the B Color component
Source:
Returns:
Enables method chaining
Type
this

addG(g) → {this}


Adds r to the Color.g
Result is clamped between 0 and 255
This:
Parameters:
Name Type Description
g Number value to add the G Color component
Source:
Returns:
Enables method chaining
Type
this

addR(r) → {this}


Adds r to the Color.r
Result is clamped between 0 and 255
This:
Parameters:
Name Type Description
r Number value to add the R Color component
Source:
Returns:
Enables method chaining
Type
this

clone() → {MC.Color}


Clones the current Color and returns a NEW copy
Source:
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:
Source:
Returns:
Enables method chaining
Type
this

lerp(Target, Ratio) → {this}


Shifts the color towards a second Color, by the ratio provided
This:
Parameters:
Name Type Description
Target MC.Color Color to be shifted towards
Ratio Number ratio of the shift, Values are capped between 0-1
Source:
Throws:
Console warning if a non-MC.Color is passed in. Color itself is unchanged
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:
Parameters:
Name Type Description
b Number value to subtract from the B Color component
Source:
Returns:
Enables method chaining
Type
this

minusG(g) → {this}


Subtracts r from the Color.g
Result is clamped between 0 and 255
This:
Parameters:
Name Type Description
g Number value to subtract from the G Color component
Source:
Returns:
Enables method chaining
Type
this

minusR(r) → {this}


Subracts r from the Color.r
Result is clamped between 0 and 255
This:
Parameters:
Name Type Description
r Number value to subtract from the R Color component
Source:
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:
Source:
Returns:
Type
string

rgba() → {string}


Returns a string of the Color attributes in rbga format e.g. "rgba(120,45,67,0.34)"
Source:
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)
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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:
Source:
Returns:
Enables method chaining
Type
this

toHex() → {string}


Returns the RGB value of a {MC.Color} in hex format. e.g. "#AA05F5"
This:
Source:
Returns:
Type
string

toSepia() → {this}


Converts Color to Sepia
See this link for more info (opens in a new window)
This:
Source:
Returns:
Enables method chaining
Type
this