Packageorg.juicekit.flare.util
Classpublic class Colors

This class supplies utility methods for working with colors. Derived from the Flare Colors class extended with elements of the NodeBox colors module (http://nodebox.net/code/index.php/Colors). Synonyms in parentheses. Color construction functions grey rgba hsv setAlpha setHue setSaturation setValue (setBrightness) setHsv adjustHsv -- perform relative adjustments adjustHue adjustSaturation adjustValue (adjustBrightness) Color properties hue (h) saturation (s) value (brightness, v, b) r g b a luminance (luminanceFromWhite) luminanceFromBlack isGrey (isGray) isBlack isWhite isTransparent Color manipulation functions: All methods the same as NodeBox except where noted. darker (darken) lighter (lighten) desaturate saturate adjustContrast complement analog rotateColorwheel -- rotate on an artistic colorwheel darker2 (flare routine) lighter2 (flare routine) desaturate2 (flare routine) interpolate interpolate_hsv luminosityDifference brightnessDifference colorDifference white_or_black getDesaturationMatrix getBackgroundColor



Public Properties
 PropertyDefined by
  adjustBrightness : Function
Colors
  brightness : Function
Brightness and v are synonyms for value
Colors
  darker : Function
Colors
  desaturationMatrix : Array
[static][read-only] A color transform matrix that desaturates colors to corresponding grayscale values.
Colors
  h : Function
h is a synonym for hue
Colors
  isGray : Function
Colors
  lighter : Function
Colors
  luminanceFromWhite : Function
Colors
  s : Function
s is a synonym for saturation
Colors
  setBrightness : Function
set_brightness is a synonym for set_value.
Colors
  v : Function
Colors
Public Methods
 MethodDefined by
  
Constructor, throws an error if called, as this is an abstract class.
Colors
  
a(c:uint):uint
[static] Returns the alpha component of a color value
Colors
  
adjustContrast(c:uint, step:Number = 0.1):uint
[static] (NodeBox) Adjust the contrast of an input color
Colors
  
adjustHsv(color:uint, h:Number = 0, s:Number = 0, v:Number = 0, a:uint = 255):uint
[static] Returns the RGB color value for a color adjusted by factors in HSV (hue, saturation, value) color space.
Colors
  
adjustHue(color:uint, h:Number = 0, a:uint = 255):uint
[static]
Colors
  
adjustSaturation(color:uint, s:Number = 0, a:uint = 255):uint
[static]
Colors
  
adjustStyle(cssSelector:String, cssProperty:String, colorAdjustmentFunction:Function):void
[static] Adjust a style declaration using one of the color adjustments For example, to darken the text color of all buttons adjustStyle('Button', 'color', Colors.darken);
Colors
  
adjustValue(color:uint, v:Number = 0, a:uint = 255):uint
[static]
Colors
  
analog(c:uint, angle:Number = 0.0555, d:Number = 0.5):uint
[static] Return colors that are similar to c
Colors
  
b(c:uint):uint
[static] Returns the blue component of a color value
Colors
  
brighter2(c:uint, s:Number = 1):uint
[static] Get a brighter shade of an input color.
Colors
  
brightnessDifference(c1:uint, c2:uint):Number
[static] Determine the brightness difference between colors.
Colors
  
clamp(val:Number, minval:Number = 0.0, maxval:Number = 1.0):Number
[static] COLOR UTILITY FUNCTIONS
Colors
  
colorDifference(c1:uint, c2:uint):Number
[static] Determine the color difference between colors.
Colors
  
complement(c:uint):uint
[static] Return a complementary color using the artistic colorwheel
Colors
  
darken(c:uint, step:Number = 0.1):uint
[static] COLOR MANIPULATION FUNCTIONS
Colors
  
darker2(c:uint, s:Number = 1):uint
[static] (Flare) Get a darker shade of an input color.
Colors
  
desaturate(c:uint, step:Number = 0.1):uint
[static] (NodeBox) Get a less saturated shade of an input color
Colors
  
desaturate2(c:uint):uint
[static] Get a completely desaturated shade of an input color.
Colors
  
g(c:uint):uint
[static] Returns the green component of a color value
Colors
  
getBackgroundColor(obj:*):uint
[static] Get background color from a Flex object
Colors
  
gray(v:uint, a:uint = 255):uint
[static] Returns a grayscale color value with the given brightness
Colors
  
hsv(h:Number, s:Number, v:Number, a:uint = 255):uint
[static] Returns the RGB color value for a color specified in HSV (hue, saturation, value) color space.
Colors
  
hue(c:uint):Number
[static] Returns the hue component of an ARGB color.
Colors
  
interpolate(c1:uint, c2:uint, f:Number):uint
[static] Interpolate between two color values by the given mixing proportion.
Colors
  
interpolateHsv(c1:uint, c2:uint, f:Number):uint
[static] Interpolate between two color values by the given mixing proportion.
Colors
  
isBlack(c:uint):Boolean
[static] Is the color "black"
Colors
  
isGrey(c:uint):Boolean
[static] Is the color grey
Colors
  
isTransparent(c:uint):Boolean
[static] Is the color transparent
Colors
  
isWhite(c:uint):Boolean
[static] Is the color white
Colors
  
lighten(c:uint, step:Number = 0.1):uint
[static] (NodeBox) Get a lighter shade of an input color.
Colors
  
luminance(c:uint):Number
[static] Returns luminosity difference from white.
Colors
  
luminanceFromBlack(c:uint):Number
[static] Returns luminosity difference from black.
Colors
  
luminosityDifference(c1:uint, c2:uint):Number
[static] Calculate the luminosity difference between two colors Luminosity values of greater than 3.0 are recommended for large text and values of greater than 4.5 are recommended for small text.
Colors
  
r(c:uint):uint
[static] Returns the red component of a color value
Colors
  
rgba(r:uint, g:uint, b:uint, a:uint = 255):uint
[static] Returns a color value with the given red, green, blue, and alpha components
Colors
  
rotateColorwheel(c:uint, angle:Number = 0.5):uint
[static] Returns a color with the hue rotated on the artistic RYB color wheel.
Colors
  
saturate(c:uint, step:Number = 0.1):uint
[static] (NodeBox) Get a more saturated shade of an input color
Colors
  
saturation(c:uint):Number
[static] Returns the saturation component of an ARGB color.
Colors
  
setAlpha(c:uint, a:uint):uint
[static] Returns a color value by updating the alpha component of another color value.
Colors
  
setHsv(color:uint, h:Number, s:Number, v:Number, a:uint = 255):uint
[static] Returns the RGB color value for a color adjusted by factors specified in specified in HSV (hue, saturation, value) color space.
Colors
  
setHue(color:uint, h:Number = 0, a:uint = 255):uint
[static]
Colors
  
setSaturation(color:uint, s:Number = 0, a:uint = 255):uint
[static]
Colors
  
setValue(color:uint, v:Number = 0, a:uint = 255):uint
[static]
Colors
  
value(c:uint):Number
[static] Returns the value (brightness) component of an ARGB color.
Colors
  
whiteOrBlack(c:uint):uint
[static] Determines if white or black would be a better color for text labels given a background color.
Colors
Property detail
adjustBrightnessproperty
public var adjustBrightness:Function
brightnessproperty 
public var brightness:Function

Brightness and v are synonyms for value

darkerproperty 
public var darker:Function
desaturationMatrixproperty 
desaturationMatrix:Array  [read-only]

A color transform matrix that desaturates colors to corresponding grayscale values. Can be used with the flash.filters.ColorMatrixFilter class.

Implementation
    public static function get desaturationMatrix():Array
hproperty 
public var h:Function

h is a synonym for hue

isGrayproperty 
public var isGray:Function
lighterproperty 
public var lighter:Function
luminanceFromWhiteproperty 
public var luminanceFromWhite:Function
sproperty 
public var s:Function

s is a synonym for saturation

setBrightnessproperty 
public var setBrightness:Function

set_brightness is a synonym for set_value.

vproperty 
public var v:Function
Constructor detail
Colors()constructor
public function Colors()

Constructor, throws an error if called, as this is an abstract class.

Method detail
a()method
public static function a(c:uint):uint

Returns the alpha component of a color value

Parameters
c:uint — the color value

Returns
uint — the alpha component
adjustContrast()method 
public static function adjustContrast(c:uint, step:Number = 0.1):uint

(NodeBox) Adjust the contrast of an input color

Parameters
c:uint — a color value
 
step:Number (default = 0.1) — an optional step value, default=0.1

Returns
uint — a darkened color value
adjustHsv()method 
public static function adjustHsv(color:uint, h:Number = 0, s:Number = 0, v:Number = 0, a:uint = 255):uint

Returns the RGB color value for a color adjusted by factors in HSV (hue, saturation, value) color space.

Parameters
color:uint — the color to adjust
 
h:Number (default = 0) — the hue, a value between -1.0 and 1.0
 
s:Number (default = 0) — the saturation, a value between -1.0 and 1.0 -1.0 fully desaturates, 1.0 fully saturates the color
 
v:Number (default = 0) — the value (brightness), a value between -1.0 and 1.0
 
a:uint (default = 255) — the (optional) alpha value, an integer between 0 and 255 (255 is the default)

Returns
uint — the corresponding RGB color value
adjustHue()method 
public static function adjustHue(color:uint, h:Number = 0, a:uint = 255):uintParameters
color:uint
 
h:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
adjustSaturation()method 
public static function adjustSaturation(color:uint, s:Number = 0, a:uint = 255):uintParameters
color:uint
 
s:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
adjustStyle()method 
public static function adjustStyle(cssSelector:String, cssProperty:String, colorAdjustmentFunction:Function):void

Adjust a style declaration using one of the color adjustments For example, to darken the text color of all buttons adjustStyle('Button', 'color', Colors.darken);

Parameters
cssSelector:String — a string indicating the css selector, e.g., "Button", ".myStyle"
 
cssProperty:String — the css property to change, e.g., "color", "backgroundColor"
 
colorAdjustmentFunction:Function — a function with signature f(color:uint):uint that adjusts the color
adjustValue()method 
public static function adjustValue(color:uint, v:Number = 0, a:uint = 255):uintParameters
color:uint
 
v:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
analog()method 
public static function analog(c:uint, angle:Number = 0.0555, d:Number = 0.5):uint

Return colors that are similar to c

Parameters
c:uint — an initial color
 
angle:Number (default = 0.0555) — amount of random hue variation, 0=no variation, 0.5=maximum variation default is 0.0555
 
d:Number (default = 0.5) — amount of saturation and value variation default is 0.5

Returns
uint
b()method 
public static function b(c:uint):uint

Returns the blue component of a color value

Parameters
c:uint — the color value

Returns
uint — the blue component
brighter2()method 
public static function brighter2(c:uint, s:Number = 1):uint

Get a brighter shade of an input color.

Parameters
c:uint — a color value
 
s:Number (default = 1)

Returns
uint — a brighter color value
brightnessDifference()method 
public static function brightnessDifference(c1:uint, c2:uint):Number

Determine the brightness difference between colors. Brightness differences greater than 125 are recommended. However, this algorithm is considered inferior to luminosityDifference.

Parameters
c1:uint
 
c2:uint

Returns
Number
clamp()method 
public static function clamp(val:Number, minval:Number = 0.0, maxval:Number = 1.0):Number

COLOR UTILITY FUNCTIONS

Parameters
val:Number
 
minval:Number (default = 0.0)
 
maxval:Number (default = 1.0)

Returns
Number
colorDifference()method 
public static function colorDifference(c1:uint, c2:uint):Number

Determine the color difference between colors. Color differences greater than 500 are recommended. However, this algorithm is considered inferior to luminosityDifference.

Parameters
c1:uint
 
c2:uint

Returns
Number
complement()method 
public static function complement(c:uint):uint

Return a complementary color using the artistic colorwheel

Parameters
c:uint

Returns
uint
darken()method 
public static function darken(c:uint, step:Number = 0.1):uint

COLOR MANIPULATION FUNCTIONS

Parameters
c:uint
 
step:Number (default = 0.1)

Returns
uint
darker2()method 
public static function darker2(c:uint, s:Number = 1):uint

(Flare) Get a darker shade of an input color.

Parameters
c:uint — a color value
 
s:Number (default = 1)

Returns
uint — a darkened color value
desaturate()method 
public static function desaturate(c:uint, step:Number = 0.1):uint

(NodeBox) Get a less saturated shade of an input color

Parameters
c:uint — a color value
 
step:Number (default = 0.1) — an optional step value, default=0.1

Returns
uint — a darkened color value
desaturate2()method 
public static function desaturate2(c:uint):uint

Get a completely desaturated shade of an input color.

Parameters
c:uint — a color value

Returns
uint — a desaturated color value
g()method 
public static function g(c:uint):uint

Returns the green component of a color value

Parameters
c:uint — the color value

Returns
uint — the green component
getBackgroundColor()method 
public static function getBackgroundColor(obj:*):uint

Get background color from a Flex object

Parameters
obj:*

Returns
uint
gray()method 
public static function gray(v:uint, a:uint = 255):uint

Returns a grayscale color value with the given brightness

Parameters
v:uint — the brightness component (0-255)
 
a:uint (default = 255) — the alpha component (0-255, 255 by default)

Returns
uint — the color value
hsv()method 
public static function hsv(h:Number, s:Number, v:Number, a:uint = 255):uint

Returns the RGB color value for a color specified in HSV (hue, saturation, value) color space.

Parameters
h:Number — the hue, a value between 0 and 1
 
s:Number — the saturation, a value between 0 and 1
 
v:Number — the value (brighntess), a value between 0 and 1
 
a:uint (default = 255) — the (optional) alpha value, an integer between 0 and 255 (255 is the default)

Returns
uint — the corresponding RGB color value
hue()method 
public static function hue(c:uint):Number

Returns the hue component of an ARGB color.

Parameters
c:uint — the input color

Returns
Number — the hue component of the color is HSV color space as a number between 0 and 1
interpolate()method 
public static function interpolate(c1:uint, c2:uint, f:Number):uint

Interpolate between two color values by the given mixing proportion. A mixing fraction of 0 will result in c1, a value of 1.0 will result in c2, and value of 0.5 will result in the color mid-way between the two in RGB color space.

Parameters
c1:uint — the starting color
 
c2:uint — the target color
 
f:Number — a fraction between 0 and 1 controlling the interpolation

Returns
uint — the interpolated color
interpolateHsv()method 
public static function interpolateHsv(c1:uint, c2:uint, f:Number):uint

Interpolate between two color values by the given mixing proportion. A mixing fraction of 0 will result in c1, a value of 1.0 will result in c2, and value of 0.5 will result in the color mid-way between the two in HSV color space.

Parameters
c1:uint — the starting color
 
c2:uint — the target color
 
f:Number — a fraction between 0 and 1 controlling the interpolation

Returns
uint — the interpolated color
isBlack()method 
public static function isBlack(c:uint):Boolean

Is the color "black"

Parameters
c:uint — a color value

Returns
Boolean — a boolean indicating if the color is black black is defined fuzzily
isGrey()method 
public static function isGrey(c:uint):Boolean

Is the color grey

Parameters
c:uint — a color value

Returns
Boolean — a boolean indicating if the color is grey
isTransparent()method 
public static function isTransparent(c:uint):Boolean

Is the color transparent

Parameters
c:uint — a color value

Returns
Boolean — a boolean indicating if the color is white
isWhite()method 
public static function isWhite(c:uint):Boolean

Is the color white

Parameters
c:uint — a color value

Returns
Boolean — a boolean indicating if the color is white
lighten()method 
public static function lighten(c:uint, step:Number = 0.1):uint

(NodeBox) Get a lighter shade of an input color.

Parameters
c:uint — a color value
 
step:Number (default = 0.1) — an optional step value, default=0.1

Returns
uint — a lightened color value
luminance()method 
public static function luminance(c:uint):Number

Returns luminosity difference from white.

Parameters
c:uint

Returns
Number
luminanceFromBlack()method 
public static function luminanceFromBlack(c:uint):Number

Returns luminosity difference from black.

Parameters
c:uint

Returns
Number
luminosityDifference()method 
public static function luminosityDifference(c1:uint, c2:uint):Number

Calculate the luminosity difference between two colors Luminosity values of greater than 3.0 are recommended for large text and values of greater than 4.5 are recommended for small text. For more discussion see: http://juicystudio.com/article/luminositycontrastratioalgorithm.php http://www.d.umn.edu/itss/support/Training/Online/webdesign/color.html#contrast

Parameters
c1:uint — the first color
 
c2:uint — the second color

Returns
Number
r()method 
public static function r(c:uint):uint

Returns the red component of a color value

Parameters
c:uint — the color value

Returns
uint — the red component
rgba()method 
public static function rgba(r:uint, g:uint, b:uint, a:uint = 255):uint

Returns a color value with the given red, green, blue, and alpha components

Parameters
r:uint — the red component (0-255)
 
g:uint — the green component (0-255)
 
b:uint — the blue component (0-255)
 
a:uint (default = 255) — the alpha component (0-255, 255 by default)

Returns
uint — the color value
rotateColorwheel()method 
public static function rotateColorwheel(c:uint, angle:Number = 0.5):uint

Returns a color with the hue rotated on the artistic RYB color wheel. An artistic color wheel has slightly different opposites (e.g. purple-yellow instead of purple-lime). It is mathematically incorrect but generally assumed to provide better complementary colors. http://en.wikipedia.org/wiki/RYB_color_model Implementation and selected comments from NodeBox colors module

Parameters
c:uint — the color to rotate
 
angle:Number (default = 0.5) — a value between 0 and 1 indicating the angle to rotate the color, 0.5 returns the complementary color

Returns
uint
saturate()method 
public static function saturate(c:uint, step:Number = 0.1):uint

(NodeBox) Get a more saturated shade of an input color

Parameters
c:uint — a color value
 
step:Number (default = 0.1) — an optional step value, default=0.1

Returns
uint — a darkened color value
saturation()method 
public static function saturation(c:uint):Number

Returns the saturation component of an ARGB color.

Parameters
c:uint — the input color

Returns
Number — the saturation of the color is HSV color space as a number between 0 and 1
setAlpha()method 
public static function setAlpha(c:uint, a:uint):uint

Returns a color value by updating the alpha component of another color value.

Parameters
c:uint — a color value
 
a:uint — the desired alpha component (0-255)

Returns
uint — a color value with adjusted alpha component
setHsv()method 
public static function setHsv(color:uint, h:Number, s:Number, v:Number, a:uint = 255):uint

Returns the RGB color value for a color adjusted by factors specified in specified in HSV (hue, saturation, value) color space.

Parameters
color:uint — the color to adjust
 
h:Number — the hue, a value between 0.0 and 1.0. This will override the hue for the color
 
s:Number — the saturation, a value between 0.0 and 1.0. This will override the saturation for the color. 1.0 if fully saturated.
 
v:Number — the value (brightness), a value between 0.0 and 1.0. This will override the value for the color
 
a:uint (default = 255) — the (optional) alpha value, an integer between 0 and 255 (255 is the default)

Returns
uint — the corresponding RGB color value
setHue()method 
public static function setHue(color:uint, h:Number = 0, a:uint = 255):uintParameters
color:uint
 
h:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
setSaturation()method 
public static function setSaturation(color:uint, s:Number = 0, a:uint = 255):uintParameters
color:uint
 
s:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
setValue()method 
public static function setValue(color:uint, v:Number = 0, a:uint = 255):uintParameters
color:uint
 
v:Number (default = 0)
 
a:uint (default = 255)

Returns
uint
value()method 
public static function value(c:uint):Number

Returns the value (brightness) component of an ARGB color.

Parameters
c:uint — the input color

Returns
Number — the value component of the color is HSV color space as a number between 0 and 1
whiteOrBlack()method 
public static function whiteOrBlack(c:uint):uint

Determines if white or black would be a better color for text labels given a background color.

Parameters
c:uint — the proposed background color

Returns
uint