Nate Cook

Downloads

AdvancedColor Object

View source: AS2.0 | AS1.0
Download (27K)

The AdvancedColor object essentially extends the built-in Color object by adding the ability to specify color for a movie clip in any of the RGB, HLS or HSV/B color spaces. It also provides static methods that allow direct conversion between color spaces.

Usage

new AdvancedColor(target)
The constructor for the AdvancedColor class. This works the same way as the Color object—the object is initialized with a movie clip as its target, and any getter and setter functions have their effect on that clip.
Undocumented here are the methods of the built-in Color object: setRGB(0xRRGGBB), getRGB(), setTransform(trans), and getTransform() because they work in exactly the same way.
setRGBComponent(red, green, blue)
Works similarly to the setRGB method, but takes the color components as three separate arguments instead of as a single hex value. These are on a scale of 0 to 256, and you can pass in decimal (e.g., 204) or hex values (e.g., 0xCC).
setHLSComponent(hue, luminosity, saturation)
setHSVComponent(hue, saturation, value)
These both work as the method above, but take values specific to their own color spaces. The hue parameter for both methods is specified in degrees on a scale from 0 to 360, while the others are percentages on a scale of 0 to 100. You can play with these values in the above example to get a sense of how they all relate.
getRGBComponent()
getHLSComponent()
getHSVComponent()
Each of these functions returns an object containing the relevant values on the scales specified above. RGB values are labeled as r, g and b; HLS as h, l and s; HSV as, you guessed it, h, s and v.
AdvancedColor.HLStoRGB(hue, lum, sat)
AdvancedColor.RGBtoHLS(red, green, blue)
AdvancedColor.HSVtoRGB(hue, sat, val)
AdvancedColor.RGBtoHSV(red, green, blue)
AdvancedColor.HLStoHSV(hue, lum, sat)
AdvancedColor.HSVtoHLS(hue, sat, val)
These are static methods of the AdvancedColor class for doing transformations between color spaces when you aren't trying to apply that color to a movie clip. These take float values between 0 and 1 for all parameters except hue, which is still on the 0 to 360 scale.

Background

Personally, I think RGB is a very weak model for thinking about color, simply because the results of combinations don't really reflect our perceptions in the real world. Red and green make yellow? Huh? Hue-based color spaces, on the other hand, are much more comfortable as they assign values to the properties that I, at least, use to describe color—a bright green, sort of a dusty dark pink, etc.

If you're interested in more background/technical information, you can check out some information on color spaces and transformations between them. That second link was the source for the algorithms in this library.

About

Nate Cook is a freelance interactive developer living and working in Chicago.