Color.js
Summary
No overview generated for 'Color.js'
draw2d.Color=function( red, green , blue)
{
if(typeof green == "undefined")
{
var rgb = this.hex2rgb(red);
this.red= rgb[0];
this.green = rgb[1];
this.blue = rgb[2];
}
else
{
this.red= red;
this.green = green;
this.blue = blue;
}
}
draw2d.Color.prototype.type="Color";
draw2d.Color.prototype.getHTMLStyle=function()
{
return "rgb("+this.red+","+this.green+","+this.blue+")";
}
draw2d.Color.prototype.getRed=function()
{
return this.red;
}
draw2d.Color.prototype.getGreen=function()
{
return this.green;
}
draw2d.Color.prototype.getBlue=function()
{
return this.blue;
}
draw2d.Color.prototype.getIdealTextColor=function()
{
var nThreshold = 105;
var bgDelta = (this.red * 0.299) + (this.green * 0.587) + (this.blue * 0.114);
return (255 - bgDelta < nThreshold) ? new draw2d.Color(0,0,0) : new draw2d.Color(255,255,255);
}
draw2d.Color.prototype.hex2rgb=function(hexcolor)
{
hexcolor = hexcolor.replace("#","");
return(
{0:parseInt(hexcolor.substr(0,2),16),
1:parseInt(hexcolor.substr(2,2),16),
2:parseInt(hexcolor.substr(4,2),16)}
);
}
draw2d.Color.prototype.hex=function()
{
return(this.int2hex(this.red)+this.int2hex(this.green)+this.int2hex(this.blue));
}
draw2d.Color.prototype.int2hex=function(v)
{
v=Math.round(Math.min(Math.max(0,v),255));
return("0123456789ABCDEF".charAt((v-v%16)/16)+"0123456789ABCDEF".charAt(v%16));
}
draw2d.Color.prototype.darker=function(fraction)
{
var red = parseInt(Math.round (this.getRed() * (1.0 - fraction)));
var green = parseInt(Math.round (this.getGreen() * (1.0 - fraction)));
var blue = parseInt(Math.round (this.getBlue() * (1.0 - fraction)));
if (red < 0) red = 0; else if (red > 255) red = 255;
if (green < 0) green = 0; else if (green > 255) green = 255;
if (blue < 0) blue = 0; else if (blue > 255) blue = 255;
return new draw2d.Color(red, green, blue);
}
draw2d.Color.prototype.lighter=function( fraction)
{
var red = parseInt(Math.round (this.getRed() * (1.0 + fraction)));
var green = parseInt(Math.round (this.getGreen() * (1.0 + fraction)));
var blue = parseInt(Math.round (this.getBlue() * (1.0 + fraction)));
if (red < 0) red = 0; else if (red > 255) red = 255;
if (green < 0) green = 0; else if (green > 255) green = 255;
if (blue < 0) blue = 0; else if (blue > 255) blue = 255;
return new draw2d.Color(red, green, blue);
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008