PDG engine v0.9.5
 All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | Public Attributes | List of all members
Color Class Reference

color in RGB space, with optional alpha More...

Public Member Functions

 Color ()
 create a color More...
 
 Color (number c)
 create a color from a single 32 bit A-RGB color value More...
 
 Color (string colorstr)
 create a color by CSS color string More...
 
 Color (number r, number g, number b, number alpha=1)
 create a color with RGB values More...
 
Color assign (Color color)
 copy a color More...
 
 convertToGrayscale ()
 convert the color to a matching shade of grey More...
 
boolean equals (Color color)
 check if this color is the same as another More...
 
boolean notEquals (Color color)
 check if this color is different than another color More...
 

Public Attributes

number alpha
 alpha channel: 0.0 transparent ... 1.0 solid More...
 
number blue
 blue component: 0.0 no blue ... 1.0 max blue More...
 
number green
 green component: 0.0 no green ... 1.0 max green More...
 
number red
 red component: 0.0 no red ... 1.0 max red More...
 

Detailed Description

color in RGB space, with optional alpha

Color is in the global namespace, so you don't need the pdg prefix, even though it will work if you use it

var c = new Color(); // this works
var c2 = new pdg.Color(); // this works too

RGB Color Space works by mixing red (R), green (G) and blue (B) light to form all possible colors. Here's a nice color wheel to illustrate.

Color Wheel

The optional Alpha Channel is used to determine how translucent the color is, ie: how much the underlying colors show through. For Alpha, 1.0 is completely solid/opaque, and 0.0 is completely transparent. Whenever an Alpha value is not given, 1.0 is assumed.

Constructor & Destructor Documentation

Color ( )

create a color

Creates a color with all RGB values set to zero, and Alpha channel set to 1, ie: solid black.

Color ( number  c)

create a color from a single 32 bit A-RGB color value

Creates a color from a single 32 bit RGB value with an Alpha channel. It's usually most convenient to express the number in hexadecimal, since it's easier to see the components:

var col = new pdg.Color(0xff004488);

In the example above, the A-RGB component values are represented as:

ff 00 44 88
A  R  G  B
See Also
Color(string)
Color(number, number, number, number)
Color ( string  colorstr)

create a color by CSS color string

Creates a color from a CSS color value string (ie: #FFF or #FFFFFF); or from a color name. For example:

var gray = new pdg.Color('#888'); // a gray color (RGB 888888)
var green = new pdg.Color('#008800'); // a green color (RGB 008800)
var teal = new pdg.Color('teal'); // the CSS teal color

Supported Color names:**

Web Colors
See Also
Color(number)
Color(number, number, number, number)
Color ( number  r,
number  g,
number  b,
number  alpha = 1 
)

create a color with RGB values

Create a color by giving the Red, Green and Blue values separately, with an optional alpha channel. Values can be given either in the range of 0.0 to 1.0. If no alpha value is given, 1.0 is used, making the color completely solid.

var white = new Color(1.0, 1.0, 1.0);
var translucentWhite = new Color(1.0, 1.0, 1.0, 0.5);
See Also
Color(number)
Color(string)

Member Function Documentation

assign ( Color  color)

copy a color

Sets this color to be the same as another color

var c1 = new Color('teal');
var c2 = new Color('black');
c1.assign(c2);
console.log('c1 is now '+c1);

Output:

c1 is now Color(0,0,0)
Returns
the color (c1 in the example)
Note
Unlike a simple assignment (c1 = c2), assign() copies the values but leaves c1 and c2 independent. Simple assignment causes c1 and c2 to point to the same data, so changing one changes the other.
convertToGrayscale ( )

convert the color to a matching shade of grey

grayscale
equals ( Color  color)

check if this color is the same as another

Returns
true if the colors are the same, false if not
notEquals ( Color  color)

check if this color is different than another color

Returns
true if the colors are different, false if not

Member Data Documentation

alpha

alpha channel: 0.0 transparent ... 1.0 solid

blue

blue component: 0.0 no blue ... 1.0 max blue

green

green component: 0.0 no green ... 1.0 max green

red

red component: 0.0 no red ... 1.0 max red

User Comments