Packagesekati.utils
Classpublic class ColorUtil

Static class wrapping various Color utilities.

See also

http://en.wikipedia.org/wiki/HSV_color_space


Public Methods
 MethodDefined by
  
ColorUtil Static Constructor
ColorUtil
  
averageBlue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int
[static] Sample & average the Blue (RGB) value from a display object or one of its region.
ColorUtil
  
averageGreen(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int
[static] Sample & average the Green (RGB) value from a display object or one of its region.
ColorUtil
  
averageHue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int
[static] Sample & average the Hue (HSL) value from a display object or one of its region.
ColorUtil
  
averageLightness(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int
[static] Sample & average the Lightness (HSL) value from a display object or one of its region.
ColorUtil
  
averageRed(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int
[static] Sample & average the Red (RGB) value from a display object or one of its region.
ColorUtil
  
averageSaturation(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number
[static] Sample & average the Saturation (HSL) value from a display object or one of its region.
ColorUtil
  
averageValue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number
[static] Sample & average the Value (HSV) value from a display object or one of its region.
ColorUtil
  
changeContrast(hex:Number, inc:Number):Number
[static] Change the contrast of a hexidecimal Number by a certain increment
ColorUtil
  
componentsFromHex(hex:uint):Object
[static] Convert an RGB hexidecimal value to an object containing its R,G,B components.
ColorUtil
  
getColor(src:DisplayObject, x:uint = 0, y:uint = 0, getAlpha:Boolean = false):uint
[static] Return the (A)RGB hexadecimal color value of a DisplayObject.
ColorUtil
  
getHSLComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object
[static] Get the HSL components from a DisplayObject.
ColorUtil
  
getHSVComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object
[static] Get the HSV components from a DisplayObject.
ColorUtil
  
getRGBComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object
[static] Get the RGB components from a DisplayObject.
ColorUtil
  
getTransform(src:DisplayObject):Object
[static] Returns the transform value set by the last setTransform() call.
ColorUtil
  
hexFromComponents(r:uint, g:uint, b:uint):uint
[static] Convert individual R,G,B values to a hexidecimal value.
ColorUtil
  
hexFromPercentages(rgbObj:Object):uint
[static] Convert an RGB Object to a hexidecimal color value.
ColorUtil
  
HSLtoHSV(hue:Number, luminance:Number, saturation:Number):Object
[static] Convert HSL to HSV using RGB conversions: color preservation may be dubious.
ColorUtil
  
HSLtoRGB(hue:Number, luminance:Number, saturation:Number):Object
[static] Convert HSL values to RGB values.
ColorUtil
  
HSVtoHSL(hue:Number, saturation:Number, value:Number):Object
[static] Convert HSV to HLS using RGB conversions: color preservation may be dubious.
ColorUtil
  
HSVtoRGB(hue:Number, saturation:Number, value:Number):Object
[static] Convert HSV values to RGB values.
ColorUtil
  
HueToRGB(min:Number, max:Number, hue:Number):Object
[static] Convert hue to RGB values using a linear transformation.
ColorUtil
  
invertColor(src:DisplayObject):void
[static] Inverts the color of the DisplayObject.
ColorUtil
  
randomColor():uint
[static] Generate a random hexidecimal color.
ColorUtil
  
resetColor(src:DisplayObject):void
[static] Reset the color of the DisplayObject to its original view (pre-ColorTransformed).
ColorUtil
  
RGBtoHSL(red:Number, green:Number, blue:Number):Object
[static] Convert an RGB Hexidecimal value to HSL values
ColorUtil
  
RGBtoHSV(red:Number, green:Number, blue:Number):Object
[static] Convert RGB values to HSV values.
ColorUtil
  
RGBToHue(red:Number, green:Number, blue:Number):uint
[static] Convert RGB values to a hue using a linear transformation.
ColorUtil
  
setColor(src:DisplayObject, hex:uint):void
[static] Set the (A)RGB hexadecimal color value of a DisplayObject using ColorTransform.
ColorUtil
  
setHSLComponent(src:DisplayObject, h:Number, l:Number, s:Number):void
[static] Set the color of a DisplayObject from HSL components.
ColorUtil
  
setHSVComponent(src:DisplayObject, h:Number, s:Number, v:Number):void
[static] Set the color of a DisplayObject from HSV components.
ColorUtil
  
setRGBComponent(src:DisplayObject, r:Number, g:Number, b:Number):void
[static] Set the color of a DisplayObject from RGB components.
ColorUtil
  
setTransform(src:DisplayObject, transformObject:Object):void
[static] Set ColorTransform information for a DisplayObject.
ColorUtil
  
toColor(str:String):uint
[static] Parse a String representation of a color (hex or html) to uint.
ColorUtil
  
toHexString(hex:uint):String
[static] Convert a hexidecimal number to a string representation with ECMAScript notation: 0xrrggbb.
ColorUtil
  
toHTML(hex:uint):String
[static] Convert a hexidecimal number to a string representation with HTML notation: #rrggbb.
ColorUtil
Public Constants
 ConstantDefined by
  HUE_MAX : uint = 360
[static]
ColorUtil
  PCT_MAX : uint = 100
[static]
ColorUtil
  RGB_MAX : uint = 256
[static]
ColorUtil
Constructor detail
ColorUtil()constructor
public function ColorUtil()

ColorUtil Static Constructor

Method detail
averageBlue()method
public static function averageBlue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int

Sample & average the Blue (RGB) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
int — the sampled average blue value on a scale of 0-255.
averageGreen()method 
public static function averageGreen(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int

Sample & average the Green (RGB) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
int — the sampled average green value on a scale of 0-255.
averageHue()method 
public static function averageHue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int

Sample & average the Hue (HSL) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
int — the sampled average hue value on a scale of 0-360.
averageLightness()method 
public static function averageLightness(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int

Sample & average the Lightness (HSL) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
int — the sampled average lightness value on a scale of 0-255.
averageRed()method 
public static function averageRed(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):int

Sample & average the Red (RGB) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
int — the sampled average red value on a scale of 0-255.
averageSaturation()method 
public static function averageSaturation(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number

Sample & average the Saturation (HSL) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
Number — the sampled average saturation value on a scale of 0-1.
averageValue()method 
public static function averageValue(src:DisplayObject, accuracy:Number = 0.01, region:Rectangle = null):Number

Sample & average the Value (HSV) value from a display object or one of its region.

Parameters
src:DisplayObject — of the display object.
 
accuracy:Number (default = 0.01) — percentage of pixels to sample when averaging.
 
region:Rectangle (default = null) — to sample from [Default: null = entire src object].

Returns
Number — the sampled average lightness value on a scale of 0-1.
changeContrast()method 
public static function changeContrast(hex:Number, inc:Number):Number

Change the contrast of a hexidecimal Number by a certain increment

Parameters
hex:Number — color value to shift contrast on
 
inc:Number — increment value to shift

Returns
Number — new hex color value
componentsFromHex()method 
public static function componentsFromHex(hex:uint):Object

Convert an RGB hexidecimal value to an object containing its R,G,B components. TODO - refactor to getRGB or toRGBComponents

Parameters
hex:uint

Returns
Object
getColor()method 
public static function getColor(src:DisplayObject, x:uint = 0, y:uint = 0, getAlpha:Boolean = false):uint

Return the (A)RGB hexadecimal color value of a DisplayObject.

Parameters
src:DisplayObject — of the display object.
 
x:uint (default = 0) — position to sample.
 
y:uint (default = 0) — position to sample.
 
getAlpha:Boolean (default = false) — if true return is RGBA, else RGB.

Returns
uint
getHSLComponent()method 
public static function getHSLComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object

Get the HSL components from a DisplayObject.

Parameters
src:DisplayObject — to sample color from.
 
x:uint (default = 0) — location to sample.
 
y:uint (default = 0) — location to sample.

Returns
Object — component object.
getHSVComponent()method 
public static function getHSVComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object

Get the HSV components from a DisplayObject.

Parameters
src:DisplayObject — to sample color from.
 
x:uint (default = 0) — location to sample.
 
y:uint (default = 0) — location to sample.

Returns
Object — component object.
getRGBComponent()method 
public static function getRGBComponent(src:DisplayObject, x:uint = 0, y:uint = 0):Object

Get the RGB components from a DisplayObject.

Parameters
src:DisplayObject — to sample color from.
 
x:uint (default = 0) — location to sample.
 
y:uint (default = 0) — location to sample.

Returns
Object — component object.
getTransform()method 
public static function getTransform(src:DisplayObject):Object

Returns the transform value set by the last setTransform() call.

Parameters
src:DisplayObject

Returns
Object — An object containing the current offset and percentage values for the color.
hexFromComponents()method 
public static function hexFromComponents(r:uint, g:uint, b:uint):uint

Convert individual R,G,B values to a hexidecimal value.

Parameters
r:uint
 
g:uint
 
b:uint

Returns
uint
hexFromPercentages()method 
public static function hexFromPercentages(rgbObj:Object):uint

Convert an RGB Object to a hexidecimal color value.

Parameters
rgbObj:Object

Returns
uint
HSLtoHSV()method 
public static function HSLtoHSV(hue:Number, luminance:Number, saturation:Number):Object

Convert HSL to HSV using RGB conversions: color preservation may be dubious.

Parameters
hue:Number
 
luminance:Number
 
saturation:Number

Returns
Object
HSLtoRGB()method 
public static function HSLtoRGB(hue:Number, luminance:Number, saturation:Number):Object

Convert HSL values to RGB values.

Parameters
hue:Number — 0 to 360.
 
luminance:Number — 0 to 1.
 
saturation:Number — 0 to 1.

Returns
Object — Object with R,G,B values on 0 to 1 scale.
HSVtoHSL()method 
public static function HSVtoHSL(hue:Number, saturation:Number, value:Number):Object

Convert HSV to HLS using RGB conversions: color preservation may be dubious.

Parameters
hue:Number
 
saturation:Number
 
value:Number

Returns
Object
HSVtoRGB()method 
public static function HSVtoRGB(hue:Number, saturation:Number, value:Number):Object

Convert HSV values to RGB values.

Parameters
hue:Number — on 0 to 360 scale.
 
saturation:Number — on 0 to 1 scale.
 
value:Number — on 0 to 1 scale.

Returns
Object — Object with R,G,B values on 0 to 1 scale.
HueToRGB()method 
public static function HueToRGB(min:Number, max:Number, hue:Number):Object

Convert hue to RGB values using a linear transformation.

Parameters
min:Number — of R,G,B.
 
max:Number — of R,G,B.
 
hue:Number — value angle hue.

Returns
Object — Object with R,G,B properties on 0-1 scale.
invertColor()method 
public static function invertColor(src:DisplayObject):void

Inverts the color of the DisplayObject.

Parameters
src:DisplayObject
randomColor()method 
public static function randomColor():uint

Generate a random hexidecimal color.

Returns
uint

See also

resetColor()method 
public static function resetColor(src:DisplayObject):void

Reset the color of the DisplayObject to its original view (pre-ColorTransformed).

Parameters
src:DisplayObject
RGBtoHSL()method 
public static function RGBtoHSL(red:Number, green:Number, blue:Number):Object

Convert an RGB Hexidecimal value to HSL values

Parameters
red:Number — 0 - 1 scale.
 
green:Number — 0 - 1 scale.
 
blue:Number — 0 - 1 scale.

Returns
Object — Object with h (hue), l (lightness), s (saturation) values:
  • h on 0 - 360 scale.
  • l on 0 - 255 scale.
  • s on 0 - 1 scale.
RGBtoHSV()method 
public static function RGBtoHSV(red:Number, green:Number, blue:Number):Object

Convert RGB values to HSV values.

Parameters
red:Number — 0 to 1 scale.
 
green:Number — 0 to 1 scale.
 
blue:Number — 0 to 1 scale.

Returns
Object — Object with H,S,V values:
  • h - on 0 to 360 scale
  • s - on 0 to 1 scale
  • v - on 0 to 1 scale
RGBToHue()method 
public static function RGBToHue(red:Number, green:Number, blue:Number):uint

Convert RGB values to a hue using a linear transformation.

Parameters
red:Number — value on 0 to 1 scale.
 
green:Number — value on 0 to 1 scale.
 
blue:Number — value on 0 to 1 scale.

Returns
uint — hue degree between 0 and 360.
setColor()method 
public static function setColor(src:DisplayObject, hex:uint):void

Set the (A)RGB hexadecimal color value of a DisplayObject using ColorTransform.

Parameters
src:DisplayObject
 
hex:uint
setHSLComponent()method 
public static function setHSLComponent(src:DisplayObject, h:Number, l:Number, s:Number):void

Set the color of a DisplayObject from HSL components.

Parameters
src:DisplayObject
 
h:Number
 
l:Number
 
s:Number
setHSVComponent()method 
public static function setHSVComponent(src:DisplayObject, h:Number, s:Number, v:Number):void

Set the color of a DisplayObject from HSV components.

Parameters
src:DisplayObject
 
h:Number
 
s:Number
 
v:Number
setRGBComponent()method 
public static function setRGBComponent(src:DisplayObject, r:Number, g:Number, b:Number):void

Set the color of a DisplayObject from RGB components.

Parameters
src:DisplayObject
 
r:Number
 
g:Number
 
b:Number
setTransform()method 
public static function setTransform(src:DisplayObject, transformObject:Object):void

Set ColorTransform information for a DisplayObject.

The colorTransformObject parameter is a generic object that you create from the new Object constructor. It has parameters specifying the percentage and offset values for the red, green, blue, and alpha (transparency) components of a color, entered in the format 0xRRGGBBAA.

Parameters
src:DisplayObject — An object created with the new Object constructor. This instance of the Object class must have the following properties that specify color transform values: ra, rb, ga, gb, ba, bb, aa, ab. These properties are explained in the above summary for the setTransform() method.
 
transformObject:Object
toColor()method 
public static function toColor(str:String):uint

Parse a String representation of a color (hex or html) to uint.

Parameters
str:String

Returns
uint
toHexString()method 
public static function toHexString(hex:uint):String

Convert a hexidecimal number to a string representation with ECMAScript notation: 0xrrggbb.

Parameters
hex:uint

Returns
String
toHTML()method 
public static function toHTML(hex:uint):String

Convert a hexidecimal number to a string representation with HTML notation: #rrggbb.

Parameters
hex:uint

Returns
String
Constant detail
HUE_MAXconstant
public static const HUE_MAX:uint = 360
PCT_MAXconstant 
public static const PCT_MAX:uint = 100
RGB_MAXconstant 
public static const RGB_MAX:uint = 256