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 var adjustBrightness:Function
public var brightness:Function Brightness and v are synonyms for value
public var darker:Function
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
public var h:Function
h is a synonym for hue
public var isGray:Function
public var lighter:Function
public var luminanceFromWhite:Function
public var s:Function
s is a synonym for saturation
public var setBrightness:Function
set_brightness is a synonym for set_value.
public var v:Function
public function Colors()
Constructor, throws an error if called, as this is an abstract class.
public static function a(c:uint):uint
Returns the alpha component of a color value
Parameters
Returns
| uint — the alpha component
|
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
|
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
|
public static function adjustHue(color:uint, h:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| h:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
public static function adjustSaturation(color:uint, s:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| s:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
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
|
public static function adjustValue(color:uint, v:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| v:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
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
public static function b(c:uint):uint
Returns the blue component of a color value
Parameters
Returns
| uint — the blue component
|
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
|
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
Returns
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
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
Returns
public static function complement(c:uint):uint
Return a complementary color using the artistic colorwheel
Parameters
Returns
public static function darken(c:uint, step:Number = 0.1):uint COLOR MANIPULATION FUNCTIONS
Parameters
| c:uint |
| |
| step:Number (default = 0.1) |
Returns
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
|
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
|
public static function desaturate2(c:uint):uint
Get a completely desaturated shade of an input color.
Parameters
Returns
| uint — a desaturated color value
|
public static function g(c:uint):uint
Returns the green component of a color value
Parameters
Returns
| uint — the green component
|
public static function getBackgroundColor(obj:*):uint
Get background color from a Flex object
Parameters
Returns
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
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
|
public static function hue(c:uint):Number
Returns the hue component of an ARGB color.
Parameters
Returns
| Number — the hue component of the color is HSV color space as a
number between 0 and 1
|
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
|
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
|
public static function isBlack(c:uint):Boolean
Is the color "black"
Parameters
Returns
| Boolean — a boolean indicating if the color is black
black is defined fuzzily
|
public static function isGrey(c:uint):Boolean
Is the color grey
Parameters
Returns
| Boolean — a boolean indicating if the color is grey
|
public static function isTransparent(c:uint):Boolean
Is the color transparent
Parameters
Returns
| Boolean — a boolean indicating if the color is white
|
public static function isWhite(c:uint):Boolean
Is the color white
Parameters
Returns
| Boolean — a boolean indicating if the color is white
|
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
|
public static function luminance(c:uint):Number
Returns luminosity difference from white.
Parameters
Returns
public static function luminanceFromBlack(c:uint):Number
Returns luminosity difference from black.
Parameters
Returns
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
public static function r(c:uint):uint
Returns the red component of a color value
Parameters
Returns
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
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
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
|
public static function saturation(c:uint):Number
Returns the saturation component of an ARGB color.
Parameters
Returns
| Number — the saturation of the color is HSV color space as a
number between 0 and 1
|
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
|
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
|
public static function setHue(color:uint, h:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| h:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
public static function setSaturation(color:uint, s:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| s:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
public static function setValue(color:uint, v:Number = 0, a:uint = 255):uintParameters
| color:uint |
| |
| v:Number (default = 0) |
| |
| a:uint (default = 255) |
Returns
public static function value(c:uint):Number
Returns the value (brightness) component of an ARGB color.
Parameters
Returns
| Number — the value component of the color is HSV color space as a
number between 0 and 1
|
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