ColorUtil

Kind of class:public class
Package:org.casalib.util
Inherits from:none
Version:09/23/08
Author:Aaron Clinger
Classpath:org.casalib.util.ColorUtil
File last modified:Thursday, 19 February 2009, 11:33:37
Provides utility functions for dealing with color.

Summary


Class methods
  • interpolateColor (begin:ColorTransform, end:ColorTransform, amount:Percent) : ColorTransform
    • Interpolates (tints) between two colors.
  • getColor (r:uint, g:uint, b:uint, a:uint = 255) : uint
    • Converts a series of individual RGB(A) values to a 32-bit ARGB color value.
  • getARGB (color:uint) : Object
    • Converts a 32-bit ARGB color value into an ARGB object.
  • getRGB (color:uint) : Object
    • Converts a 24-bit RGB color value into an RGB object.
  • getHexStringFromARGB (a:uint, r:uint, g:uint, b:uint) : String
    • Converts a 32-bit ARGB color value into a hexidecimal String representation.
  • getHexStringFromRGB (r:uint, g:uint, b:uint) : String
    • Converts an RGB color value into a hexidecimal String representation.

Class methods

getARGB

public static function getARGB (
color:uint) : Object

Converts a 32-bit ARGB color value into an ARGB object.
Parameters:
color:
The 32-bit ARGB color value.
Returns:
  • Returns an object with the properties a, r, g, and b defined.
Example:
  • var myRGB:Object = ColorUtil.getARGB(0xCCFF00FF);
    trace("Alpha = " + myRGB.a);
    trace("Red = " + myRGB.r);
    trace("Green = " + myRGB.g);
    trace("Blue = " + myRGB.b);

getColor

public static function getColor (
r:uint, g:uint, b:uint, a:uint = 255) : uint

Converts a series of individual RGB(A) values to a 32-bit ARGB color value.
Parameters:
r:
A uint from 0 to 255 representing the red color value.
g:
A uint from 0 to 255 representing the green color value.
b:
A uint from 0 to 255 representing the blue color value.
a:
A uint from 0 to 255 representing the alpha value. Default is 255.
Returns:
  • Returns a hexidecimal color as a String.
Example:
  • var hexColor : String = ColorUtil.getHexStringFromARGB(128, 255, 0, 255);
    trace(hexColor); // Traces 80FF00FF

getHexStringFromARGB

public static function getHexStringFromARGB (
a:uint, r:uint, g:uint, b:uint) : String

Converts a 32-bit ARGB color value into a hexidecimal String representation.
Parameters:
a:
A uint from 0 to 255 representing the alpha value.
r:
A uint from 0 to 255 representing the red color value.
g:
A uint from 0 to 255 representing the green color value.
b:
A uint from 0 to 255 representing the blue color value.
Returns:
  • Returns a hexidecimal color as a String.
Example:
  • var hexColor : String = ColorUtil.getHexStringFromARGB(128, 255, 0, 255);
    trace(hexColor); // Traces 80FF00FF

getHexStringFromRGB

public static function getHexStringFromRGB (
r:uint, g:uint, b:uint) : String

Converts an RGB color value into a hexidecimal String representation.
Parameters:
r:
A uint from 0 to 255 representing the red color value.
g:
A uint from 0 to 255 representing the green color value.
b:
A uint from 0 to 255 representing the blue color value.
Returns:
  • Returns a hexidecimal color as a String.
Example:
  • var hexColor : String = ColorUtil.getHexStringFromRGB(255, 0, 255);
    trace(hexColor); // Traces FF00FF

getRGB

public static function getRGB (
color:uint) : Object

Converts a 24-bit RGB color value into an RGB object.
Parameters:
color:
The 24-bit RGB color value.
Returns:
  • Returns an object with the properties r, g, and b defined.
Example:
  • var myRGB:Object = ColorUtil.getRGB(0xFF00FF);
    trace("Red = " + myRGB.r);
    trace("Green = " + myRGB.g);
    trace("Blue = " + myRGB.b);

interpolateColor

public static function interpolateColor (
begin:ColorTransform, end:ColorTransform, amount:Percent) : ColorTransform

Interpolates (tints) between two colors.
Parameters:
begin :
The start color.
end :
The finish color.
amount:
The level of interpolation between the two colors.
Returns:
  • The new interpolated color.
Usage:
  • var myColor:ColorTransform = new ColorTransform();
    myColor.color              = 0xFF0000;
    
    var box:Sprite = new Sprite();
    box.graphics.beginFill(0x0000FF);
    box.graphics.drawRect(10, 10, 250, 250);
    box.graphics.endFill();
    
    box.transform.colorTransform = ColorUtil.interpolateColor(new ColorTransform(), myColor, new Percent(0.5));
    
    this.addChild(box);