ofDoc > types > ofColor

ofColorfile

Variants

ofColor typedef
ofShortColor typedef
ofFloatColor typedef

ofColor_class

template<typename T>
class ofColor_< T >

ofColor represents a color in openFrameworks. Colors are usually defined by specifying a red, green, and blue component (RGB), and a transparency (alpha) component. You can also specify colors using hue, saturation, and brightness (HSB).

For example:

// Set red, component by component
red.r=255;
red.g=0;
red.b=0;
// Draw color is now red.
// Shorter notation is also possible.
ofColor green(0, 255, 0);
// Draw color is now green.
// ... or even shorter.
ofSetColor( ofColor(0, 0, ofRandom( 128, 255 ) );
// Draw color is now a random blue.

ofColor also enables a lot of extra functionality like using HSB instead of color spectrums, lerping or linearly interpolating between colors, and inverting colors, among other things.

ofColor is templated, which means that it has several different ways it can be created. These are probably best to leave as they are because there's already a few kinds typedefed for you. The default ofColor uses unsigned char values (0 to 255), but you can make an ofFloatColor if you want to work with floating point numbers between 0 and 1, or ofShortColor if you want to work with integers between 0 and 65,535.

Typedef PixelType Bit Depth Min. Value Max. Value
ofColor unsigned char 8 0 255
ofShortColorunsigned short 16 0 65535
ofFloatColorfloat varies 0.0 1.0

HSB

You're probably familiar with RGB colors already, but HSB is a big part of ofColor. It uses a hue value (for the standard ofColor the range for this value is between 0 and 255) to determine what the hue (the 'color' in the sense of a color in the rainbow) will be:

HSB

Approximate hues for some common colors:

  • Red: 0 (wrapped round from 255)
  • Orange: 25
  • Yellow: 42
  • Green: 85
  • Blue: 170
  • Purple: 205
  • Red: 255 (wraps round to 0)

Once you've selected a hue, you can use the saturation and brightness values to further refine the color. The saturation determines how much of the hue versus white is present and brightness determines how much hue versus black is present:

SB

In other words, saturation refers to the intensity of the color: high saturation means intense color, low saturation means washed out or black and white. Brightness refers to how light or dark the color is: high brightness means a bright color, low brightness means a dark color. If the brightness is 0 the resulting color will be black, regardless of the values of hue or saturation.

Template Parameters
PixelTypeThe data type used to represent a single pixel value.

Create an ofColor

fromHsb ()
fromHex ()

Data Accessors

Setters

set ()
setHex ()
setHue ()
setHsb ()

Modifiers

clamp ()
invert ()
lerp ()

Getters

getHex ()
getHue ()
getHsb ()
limit ()

Operators

operator<< friend
operator>> friend

Predefined Colors

white variable
gray variable
black variable
red variable
green variable
blue variable
cyan variable
magenta variable
yellow variable
aliceBlue variable
antiqueWhite variable
aqua variable
aquamarine variable
azure variable
beige variable
bisque variable
blanchedAlmond variable
blueViolet variable
brown variable
burlyWood variable
cadetBlue variable
chartreuse variable
chocolate variable
coral variable
cornflowerBlue variable
cornsilk variable
crimson variable
darkBlue variable
darkCyan variable
darkGoldenRod variable
darkGray variable
darkGrey variable
darkGreen variable
darkKhaki variable
darkMagenta variable
darkOliveGreen variable
darkorange variable
darkOrchid variable
darkRed variable
darkSalmon variable
darkSeaGreen variable
darkSlateBlue variable
darkSlateGray variable
darkSlateGrey variable
darkTurquoise variable
darkViolet variable
deepPink variable
deepSkyBlue variable
dimGray variable
dimGrey variable
dodgerBlue variable
fireBrick variable
floralWhite variable
forestGreen variable
fuchsia variable
gainsboro variable
ghostWhite variable
gold variable
goldenRod variable
grey variable
greenYellow variable
honeyDew variable
hotPink variable
indianRed variable
indigo variable
ivory variable
khaki variable
lavender variable
lavenderBlush variable
lawnGreen variable
lemonChiffon variable
lightBlue variable
lightCoral variable
lightCyan variable
lightGray variable
lightGrey variable
lightGreen variable
lightPink variable
lightSalmon variable
lightSeaGreen variable
lightSkyBlue variable
lightSlateGray variable
lightSlateGrey variable
lightSteelBlue variable
lightYellow variable
lime variable
limeGreen variable
linen variable
maroon variable
mediumAquaMarine variable
mediumBlue variable
mediumOrchid variable
mediumPurple variable
mediumSeaGreen variable
mediumSlateBlue variable
mediumTurquoise variable
mediumVioletRed variable
midnightBlue variable
mintCream variable
mistyRose variable
moccasin variable
navajoWhite variable
navy variable
oldLace variable
olive variable
oliveDrab variable
orange variable
orangeRed variable
orchid variable
paleGoldenRod variable
paleGreen variable
paleTurquoise variable
paleVioletRed variable
papayaWhip variable
peachPuff variable
peru variable
pink variable
plum variable
powderBlue variable
purple variable
rosyBrown variable
royalBlue variable
saddleBrown variable
salmon variable
sandyBrown variable
seaGreen variable
seaShell variable
sienna variable
silver variable
skyBlue variable
slateBlue variable
slateGray variable
slateGrey variable
snow variable
springGreen variable
steelBlue variable
blueSteel variable
tan variable
teal variable
thistle variable
tomato variable
turquoise variable
violet variable
wheat variable
whiteSmoke variable
yellowGreen variable

Attributes

r variable
g variable
b variable
a variable
v variable