ROOT » CORE » BASE » TColor

class TColor: public TNamed


The color creation and management class

Introduction

Colors are defined by their red, green and blue components, simply called the RGB components. The colors are also known by the hue, light and saturation components also known as the HLS components. When a new color is created the components of both color systems are computed.

At initialization time, a table of colors is generated. An existing color can be retrieved by its index:

   TColor *color = gROOT->GetColor(10);

Then it can be manipulated. For example its RGB components can be modified:

   color->SetRGB(0.1, 0.2, 0.3);

A new color can be created the following way:

   Int_t ci = 1756; // color index
   TColor *color = new TColor(ci, 0.1, 0.2, 0.3);

Two sets of colors are initialized;

  • The basic colors: colors with index from 0 to 50.
  • The color wheel: colors with indices from 300 to 1000.

Basic colors

The following image displays the 50 basic colors.
output of html602/MACRO_TColor_1.gif
{
   TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
   c->DrawColorTable();
   return c;
}

The color wheel

The wheel contains the recommended 216 colors to be used in web applications. The colors in the color wheel are created by TColor::CreateColorWheel.

Using this color set for your text, background or graphics will give your application a consistent appearance across different platforms and browsers.

Colors are grouped by hue, the aspect most important in human perception. Touching color chips have the same hue, but with different brightness and vividness.

Colors of slightly different hues clash. If you intend to display colors of the same hue together, you should pick them from the same group.

Each color chip is identified by a mnemonic (e.g. kYellow) and a number. The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file Rtypes.h that is included in all ROOT other header files. It is better to use these keywords in user code instead of hardcoded color numbers, e.g.:

   myObject.SetFillColor(kRed);
   myObject.SetFillColor(kYellow-10);
   myLine.SetLineColor(kMagenta+2);
output of html602/MACRO_TColor_3.gif
{
   TColorWheel *w = new TColorWheel();
   w->Draw();
   return w->GetCanvas();
}

Bright and dark colors

The dark and bright color are used to give 3-D effects when drawing various boxes (see TWbox, TPave, TPaveText, TPaveLabel, etc).
  • The dark colors have an index = color_index+100
  • The bright colors have an index = color_index+150
  • Two static functions return the bright and dark color number corresponding to a color index. If the bright or dark color does not exist, they are created:
          Int_t dark   = TColor::GetColorDark(color_index);
          Int_t bright = TColor::GetColorBright(color_index);
       

Grayscale view of of canvas with colors

One can toggle between a grayscale preview and the regular colored mode using TCanvas::SetGrayscale(). Note that in grayscale mode, access via RGB will return grayscale values according to ITU standards (and close to b&w printer grayscales), while access via HLS returns de-saturated grayscales. The image below shows the ROOT color wheel in grayscale mode.
output of html602/MACRO_TColor_5.gif
{
   TColorWheel *w = new TColorWheel();
   w->Draw();
   w->GetCanvas()->SetGrayscale();
   w->GetCanvas()->Modified();
   w->GetCanvas()->Update();
   return w->GetCanvas();
}

Color palettes

It is often very useful to represent a variable with a color map. The concept of "color palette" allows to do that. One color palette is active at any time. This "current palette" is set using:

gStyle->SetPalette(...);

This function has two parameters: the number of colors in the palette and an array of containing the indices of colors in the palette. The following small example demonstrates how to define and use the color palette:

output of html602/MACRO_TColor_7.gif
{
   TCanvas *c1  = new TCanvas("c1","c1",0,0,600,400);
   TF2 *f1 = new TF2("f1","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   Int_t palette[5];
   palette[0] = 15;
   palette[1] = 20;
   palette[2] = 23;
   palette[3] = 30;
   palette[4] = 32;
   gStyle->SetPalette(5,palette);
   f1->Draw("colz");
   return c1;
}

To define more a complex palette with a continuous gradient of color, one should use the static function TColor::CreateGradientColorTable(). The following example demonstrates how to proceed:

output of html602/MACRO_TColor_9.gif
{
   TCanvas *c2  = new TCanvas("c2","c2",0,0,600,400);
   TF2 *f2 = new TF2("f2","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   const Int_t Number = 3;
   Double_t Red[Number]    = { 1.00, 0.00, 0.00};
   Double_t Green[Number]  = { 0.00, 1.00, 0.00};
   Double_t Blue[Number]   = { 1.00, 0.00, 1.00};
   Double_t Length[Number] = { 0.00, 0.50, 1.00 };
   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
   f2->SetContour(nb);
   f2->SetLineWidth(1);
   f2->SetLineColor(kBlack);
   f2->Draw("surf1z");
   return c2;
}

The function TColor::CreateGradientColorTable() automatically calls gStyle->SetPalette(), so there is not need to add one.

After a call to TColor::CreateGradientColorTable() it is sometimes useful to store the newly create palette for further use. In particular, it is recommended to do if one wants to switch between several user define palettes. To store a palette in an array it is enough to do:

   Int_t MyPalette[100];
   Double_t r[]    = {0., 0.0, 1.0, 1.0, 1.0};
   Double_t g[]    = {0., 0.0, 0.0, 1.0, 1.0};
   Double_t b[]    = {0., 1.0, 0.0, 0.0, 1.0};
   Double_t stop[] = {0., .25, .50, .75, 1.0};
   Int_t FI = TColor::CreateGradientColorTable(5, stop, r, g, b, 100);
   for (int i=0;i<100;i++) MyPalette[i] = FI+i;

Later on to reuse the palette MyPalette it will be enough to do

   gStyle->SetPalette(100, MyPalette);

As only one palette is active, one need to use TExec to be able to display plots using different palettes on the same pad. The following macro illustrate this feature.

output of html602/MACRO_TColor_11.gif
//Draw color plots using different color palettes.
//Author:: Olivier Couet

#include "TStyle.h"
#include "TColor.h"
#include "TF2.h"
#include "TExec.h"
#include "TCanvas.h"


void Pal1()
{
   static Int_t  colors[50];
   static Bool_t initialized = kFALSE;

   Double_t Red[3]    = { 1.00, 0.00, 0.00};
   Double_t Green[3]  = { 0.00, 1.00, 0.00};
   Double_t Blue[3]   = { 1.00, 0.00, 1.00};
   Double_t Length[3] = { 0.00, 0.50, 1.00 };

   if(!initialized){
      Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
      for (int i=0; i<50; i++) colors[i] = FI+i;
      initialized = kTRUE;
      return;
   }
   gStyle->SetPalette(50,colors);
}

void Pal2()
{
   static Int_t  colors[50];
   static Bool_t initialized = kFALSE;

   Double_t Red[3]    = { 1.00, 0.50, 0.00};
   Double_t Green[3]  = { 0.50, 0.00, 1.00};
   Double_t Blue[3]   = { 1.00, 0.00, 0.50};
   Double_t Length[3] = { 0.00, 0.50, 1.00 };

   if(!initialized){
      Int_t FI = TColor::CreateGradientColorTable(3,Length,Red,Green,Blue,50);
      for (int i=0; i<50; i++) colors[i] = FI+i;
      initialized = kTRUE;
      return;
   }
   gStyle->SetPalette(50,colors);
}

TCanvas* multipalette() {
   TCanvas *c3  = new TCanvas("c3","C3",0,0,600,400);
   c3->Divide(2,1);
   TF2 *f3 = new TF2("f3","0.1+(1-(x-2)*(x-2))*(1-(y-2)*(y-2))",1,3,1,3);
   f3->SetLineWidth(1);
   f3->SetLineColor(kBlack);

   c3->cd(1);
   f3->Draw("surf1");
   TExec *ex1 = new TExec("ex1","Pal1();");
   ex1->Draw();
   f3->Draw("surf1 same");

   c3->cd(2);
   f3->Draw("surf1");
   TExec *ex2 = new TExec("ex2","Pal2();");
   ex2->Draw();
   f3->Draw("surf1 same");

   return c3;
}

Color transparency

To make a graphics object transparent it is enough to set its color to a transparent one. The color transparency is defined via its alpha component. The alpha value varies from 0. (fully transparent) to 1. (fully opaque). To set the alpha value of an existing color it is enough to do:

   TColor *col26 = gROOT->GetColor(26);
   col26->SetAlpha(0.01);

A new color can be created transparent the following way:

   Int_t ci = 1756;
   TColor *color = new TColor(ci, 0.1, 0.2, 0.3, "", 0.5); // alpha = 0.5

An example of tranparency usage with parallel coordinates can be found in $ROOTSYS/tutorials/tree/parallelcoordtrans.C.

To ease the creation of a transparent color the static method GetColorTransparent(Int_t color, Float_t a) is provided. In the following example the trans_red color index point to a red color 30% transparent. The alpha value of the color index kRed is not modified.

   Int_t trans_red = GetColorTransparent(kRed, 0.3);

This function is also used in the methods SetFillColorAlpha(), SetLineColorAlpha(), SetMarkerColorAlpha() and SetTextColorAlpha(). In the following example the fill color of the histogram histo is set to blue with a transparency of 35%. The color kBlue itself remains fully opaque.

   histo->SetFillColorAlpha(kBlue, 0.35);

The transparency is available on all platforms when the flagOpenGL.CanvasPreferGL is set to 1 in $ROOTSYS/etc/system.rootrc, or on Mac with the Cocoa backend. On the file output it is visible with PDF, PNG, Gif, JPEG, SVG ... but not PostScript.

 

Function Members (Methods)

public:
virtual~TColor()
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
const char*AsHexString() const
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidCopy(TObject& color) const
static voidCreateColorsCircle(Int_t offset, const char* name, UChar_t* rgb)
static voidCreateColorsGray()
static voidCreateColorsRectangle(Int_t offset, const char* name, UChar_t* rgb)
static voidCreateColorWheel()
static Int_tCreateGradientColorTable(UInt_t Number, Double_t* Stops, Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha = 1.)
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
Float_tGetAlpha() const
Float_tGetBlue() const
static Int_tGetColor(const char* hexcolor)
static Int_tGetColor(ULong_t pixel)
static Int_tGetColor(Float_t r, Float_t g, Float_t b)
static Int_tGetColor(Int_t r, Int_t g, Int_t b)
static Int_tGetColorBright(Int_t color)
static Int_tGetColorDark(Int_t color)
static Int_tGetColorPalette(Int_t i)
static Int_tGetColorTransparent(Int_t color, Float_t a)
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Float_tGetGrayscale() const
Float_tGetGreen() const
virtual voidGetHLS(Float_t& h, Float_t& l, Float_t& s) const
Float_tGetHue() const
virtual const char*TObject::GetIconName() const
Float_tGetLight() const
virtual const char*TNamed::GetName() const
Int_tGetNumber() const
static Int_tGetNumberOfColors()
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
ULong_tGetPixel() const
Float_tGetRed() const
virtual voidGetRGB(Float_t& r, Float_t& g, Float_t& b) const
Float_tGetSaturation() const
virtual const char*TNamed::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
static voidHLS2RGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
static voidHLS2RGB(Int_t h, Int_t l, Int_t s, Int_t& r, Int_t& g, Int_t& b)
static voidHLStoRGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
static voidHSV2RGB(Float_t h, Float_t s, Float_t v, Float_t& r, Float_t& g, Float_t& b)
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
static voidInitializeColors()
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
static Bool_tIsGrayscale()
Bool_tTObject::IsOnHeap() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
static ULong_tNumber2Pixel(Int_t ci)
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TColor&operator=(const TColor&)
virtual voidTObject::Paint(Option_t* option = "")
static voidPixel2RGB(ULong_t pixel, Int_t& r, Int_t& g, Int_t& b)
static voidPixel2RGB(ULong_t pixel, Float_t& r, Float_t& g, Float_t& b)
static const char*PixelAsHexString(ULong_t pixel)
virtual voidTObject::Pop()
virtual voidPrint(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
static voidRGB2HLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
static voidRGB2HLS(Int_t r, Int_t g, Int_t b, Int_t& h, Int_t& l, Int_t& s)
static voidRGB2HSV(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& s, Float_t& v)
static ULong_tRGB2Pixel(Int_t r, Int_t g, Int_t b)
static ULong_tRGB2Pixel(Float_t r, Float_t g, Float_t b)
static voidRGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
static voidSaveColor(ostream& out, Int_t ci)
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
virtual voidSetAlpha(Float_t a)
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
static voidSetGrayscale(Bool_t set = kTRUE)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
static voidSetPalette(Int_t ncolors, Int_t* colors, Float_t alpha = 1.)
virtual voidSetRGB(Float_t r, Float_t g, Float_t b)
virtual voidTNamed::SetTitle(const char* title = "")MENU
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp) const
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
TColor()
TColor(const TColor& color)
TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char* name = "", Float_t a = 1)
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()
private:
voidAllocate()
static Float_tHLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
TStringTNamed::fNameobject identifier
Int_tfNumberColor number identifier
TStringTNamed::fTitleobject title
private:
Float_tfAlphaAlpha (transparency)
Float_tfBlueFraction of Blue
Float_tfGreenFraction of Green
Float_tfHueHue
Float_tfLightLight
Float_tfRedFraction of Red
Float_tfSaturationSaturation
static Bool_tfgGrayscaleModeif set, GetColor will return grayscale
static Bool_tfgInitDonekTRUE once ROOT colors have been initialized
static TArrayIfgPaletteColor palette

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TColor()
   Default constructor.
   
 
TColor(Int_t color, Float_t r, Float_t g, Float_t b, const char* name = "", Float_t a = 1)
   Normal color constructor. Initialize a color structure.
   Compute the RGB and HLS color components.
   
 
~TColor()
   Color destructor.
   
 
TColor(const TColor& color)
   Color copy constructor.
   
 
void InitializeColors()
   Initialize colors used by the TCanvas based graphics (via TColor objects).
   This method should be called before the ApplicationImp is created (which
   initializes the GUI colors).
   
 
const char * AsHexString() const
   Return color as hexadecimal string. This string can be directly passed
   to, for example, TGClient::GetColorByName(). String will be reused so
   copy immediately if needed.
   
 
void Copy(TObject& color) const
   Copy this color to obj.
   
 
void CreateColorsGray()
   Create the Gray scale colors in the Color Wheel
   
 
void CreateColorsCircle(Int_t offset, const char* name, UChar_t* rgb)
   Create the "circle" colors in the color wheel.
   
 
void CreateColorsRectangle(Int_t offset, const char* name, UChar_t* rgb)
   Create the "rectangular" colors in the color wheel.
   
 
void CreateColorWheel()
   Static function steering the creation of all colors in the color wheel.
   
 
Int_t GetColorPalette(Int_t i)
   Static function returning the color number i in current palette.
   
 
Int_t GetNumberOfColors()
   Static function returning number of colors in the color palette.
   
 
ULong_t GetPixel() const
   Return pixel value corresponding to this color. This pixel value can
   be used in the GUI classes. This call does not work in batch mode since
   it needs to communicate with the graphics system.
   
 
void HLS2RGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
   Static method to compute RGB from HLS. The l and s are between [0,1]
   and h is between [0,360]. The returned r,g,b triplet is between [0,1].
   
 
Float_t HLStoRGB1(Float_t rn1, Float_t rn2, Float_t huei)
   Static method. Auxiliary to HLS2RGB().
   
 
void HLS2RGB(Int_t h, Int_t l, Int_t s, Int_t& r, Int_t& g, Int_t& b)
   Static method to compute RGB from HLS. The h,l,s are between [0,255].
   The returned r,g,b triplet is between [0,255].
   
 
void HSV2RGB(Float_t h, Float_t s, Float_t v, Float_t& r, Float_t& g, Float_t& b)
   Static method to compute RGB from HSV:
   
  • The hue value runs from 0 to 360.
  • The saturation is the degree of strength or purity and is from 0 to 1. Purity is how much white is added to the color, so S=1 makes the purest color (no white).
  • Brightness value also ranges from 0 to 1, where 0 is the black.
The returned r,g,b triplet is between [0,1].
 
void ls(Option_t* option = "") const
   List this color with its attributes.
   
 
void Print(Option_t* option = "") const
   Dump this color with its attributes.
   
 
void RGB2HLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
   Static method to compute HLS from RGB. The r,g,b triplet is between
   [0,1], hue is between [0,360], light and satur are [0,1].
   
 
void RGB2HSV(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& s, Float_t& v)
   Static method to compute HSV from RGB.
   
  • The input values:
    • r,g,b triplet is between [0,1].
  • The returned values:
    • The hue value runs from 0 to 360.
    • The saturation is the degree of strength or purity and is from 0 to 1. Purity is how much white is added to the color, so S=1 makes the purest color (no white).
    • Brightness value also ranges from 0 to 1, where 0 is the black.
 
void RGB2HLS(Int_t r, Int_t g, Int_t b, Int_t& h, Int_t& l, Int_t& s)
   Static method to compute HLS from RGB. The r,g,b triplet is between
   [0,255], hue, light and satur are between [0,255].
   
 
void SetRGB(Float_t r, Float_t g, Float_t b)
   Initialize this color and its associated colors.
   
 
void Allocate()
   Make this color known to the graphics system.
   
 
Int_t GetColor(const char* hexcolor)
   Static method returning color number for color specified by
   hex color string of form: #rrggbb, where rr, gg and bb are in
   hex between [0,FF], e.g. "#c0c0c0".
   
If specified color does not exist it will be created with as name "#rrggbb" with rr, gg and bb in hex between [0,FF].
 
Int_t GetColor(Float_t r, Float_t g, Float_t b)
   Static method returning color number for color specified by
   r, g and b. The r,g,b should be in the range [0,1].
   
If specified color does not exist it will be created with as name "#rrggbb" with rr, gg and bb in hex between [0,FF].
 
Int_t GetColor(ULong_t pixel)
   Static method returning color number for color specified by
   system dependent pixel value. Pixel values can be obtained, e.g.,
   from the GUI color picker.
   
 
Int_t GetColor(Int_t r, Int_t g, Int_t b)
   Static method returning color number for color specified by
   r, g and b. The r,g,b should be in the range [0,255].
   If the specified color does not exist it will be created
   with as name "#rrggbb" with rr, gg and bb in hex between
   [0,FF].
   
 
Int_t GetColorBright(Int_t color)
   Static function: Returns the bright color number corresponding to n
   If the TColor object does not exist, it is created.
   The convention is that the bright color nb = n+150
   
 
Int_t GetColorDark(Int_t color)
   Static function: Returns the dark color number corresponding to n
   If the TColor object does not exist, it is created.
   The convention is that the dark color nd = n+100
   
 
Int_t GetColorTransparent(Int_t color, Float_t a)
   Static function: Returns the transparent color number corresponding to n.
   The transparency level is given by the alpha value a.
   
 
ULong_t Number2Pixel(Int_t ci)
   Static method that given a color index number, returns the corresponding
   pixel value. This pixel value can be used in the GUI classes. This call
   does not work in batch mode since it needs to communicate with the
   graphics system.
   
 
ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b)
   Convert r,g,b to graphics system dependent pixel value.
   The r,g,b triplet must be [0,1].
   
 
ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b)
   Convert r,g,b to graphics system dependent pixel value.
   The r,g,b triplet must be [0,255].
   
 
void Pixel2RGB(ULong_t pixel, Float_t& r, Float_t& g, Float_t& b)
   Convert machine dependent pixel value (obtained via RGB2Pixel or
   via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
   The r,g,b triplet will be [0,1].
   
 
void Pixel2RGB(ULong_t pixel, Int_t& r, Int_t& g, Int_t& b)
   Convert machine dependent pixel value (obtained via RGB2Pixel or
   via Number2Pixel() or via TColor::GetPixel()) to r,g,b triplet.
   The r,g,b triplet will be [0,255].
   
 
const char * PixelAsHexString(ULong_t pixel)
   Convert machine dependent pixel value (obtained via RGB2Pixel or
   via Number2Pixel() or via TColor::GetPixel()) to a hexadecimal string.
   This string can be directly passed to, for example,
   TGClient::GetColorByName(). String will be reused so copy immediately
   if needed.
   
 
void SaveColor(ostream& out, Int_t ci)
   Save a color with index > 228 as a C++ statement(s) on output stream out.
   
 
Bool_t IsGrayscale()
   Return whether all colors return grayscale values.
   
 
void SetGrayscale(Bool_t set = kTRUE)
   Set whether all colors should return grayscale values.
   
 
Int_t CreateGradientColorTable(UInt_t Number, Double_t* Stops, Double_t* Red, Double_t* Green, Double_t* Blue, UInt_t NColors, Float_t alpha = 1.)
   Static function creating a color table with several connected linear gradients.
   
  • Number: The number of end point colors that will form the gradients. Must be at least 2.
  • Stops: Where in the whole table the end point colors should lie. Each entry must be on [0, 1], each entry must be greater than the previous entry.
  • Red, Green, Blue: The end point color values. Each entry must be on [0, 1]
  • NColors: Total number of colors in the table. Must be at least 1.
Returns a positive value on success and -1 on error.

The table is constructed by tracing lines between the given points in RGB space. Each color value may have a value between 0 and 1. The difference between consecutive "Stops" values gives the fraction of space in the whole table that should be used for the interval between the corresponding color values.

Normally the first element of Stops should be 0 and the last should be 1. If this is not true, fewer than NColors will be used in proportion with the total interval between the first and last elements of Stops.

This definition is similar to the povray-definition of gradient color tables.

For instance:

   UInt_t Number = 3;
   Double_t Red[3]   = { 0.0, 1.0, 1.0 };
   Double_t Green[3] = { 0.0, 0.0, 1.0 };
   Double_t Blue[3]  = { 1.0, 0.0, 1.0 };
   Double_t Stops[3] = { 0.0, 0.4, 1.0 };
   
This defines a table in which there are three color end points: RGB = {0, 0, 1}, {1, 0, 0}, and {1, 1, 1} = blue, red, white The first 40% of the table is used to go linearly from blue to red. The remaining 60% of the table is used to go linearly from red to white.

If you define a very short interval such that less than one color fits in it, no colors at all will be allocated. If this occurs for all intervals, ROOT will revert to the default palette.

Original code by Andreas Zoglauer (zog@mpe.mpg.de)

 
void SetPalette(Int_t ncolors, Int_t* colors, Float_t alpha = 1.)
   Static function.
   The color palette is used by the histogram classes
    (see TH1::Draw options).
   For example TH1::Draw("col") draws a 2-D histogram with cells
   represented by a box filled with a color CI function of the cell content.
   if the cell content is N, the color CI used will be the color number
   in colors[N],etc. If the maximum cell content is > ncolors, all
   cell contents are scaled to ncolors.
   

if ncolors <= 0 a default palette (see below) of 50 colors is defined. The colors defined in this palette are OK for coloring pads, labels.

   index 0->9   : grey colors from light to dark grey
   index 10->19 : "brown" colors
   index 20->29 : "blueish" colors
   index 30->39 : "redish" colors
   index 40->49 : basic colors
   

if ncolors == 1 && colors == 0, then a Pretty Palette with a Spectrum Violet->Red is created with 50 colors. That's the default rain bow palette.

Other prefined palettes with 255 colors are available when colors == 0. The following value of ncolors give access to:

   if ncolors = 51 and colors=0, a Deep Sea palette is used.
   if ncolors = 52 and colors=0, a Grey Scale palette is used.
   if ncolors = 53 and colors=0, a Dark Body Radiator palette is used.
   if ncolors = 54 and colors=0, a two-color hue palette palette is used.(dark blue through neutral gray to bright yellow)
   if ncolors = 55 and colors=0, a Rain Bow palette is used.
   if ncolors = 56 and colors=0, an inverted Dark Body Radiator palette is used.
   
(see TColor::CreateGradientColorTable for more details)

The color numbers specified in the palette can be viewed by selecting the item "colors" in the "VIEW" menu of the canvas toolbar. The color parameters can be changed via TColor::SetRGB.

Note that when drawing a 2D histogram h2 with the option "COL" or "COLZ" or with any "CONT" options using the color map, the number of colors used is defined by the number of contours n specified with: h2->SetContour(n)

 
void GetRGB(Float_t& r, Float_t& g, Float_t& b) const
{ r=GetRed(); g=GetGreen(); b=GetBlue(); }
void GetHLS(Float_t& h, Float_t& l, Float_t& s) const
{ h=GetHue(); l=GetLight(); s=GetSaturation(); }
Int_t GetNumber() const
{ return fNumber; }
Float_t GetRed() const
{ return IsGrayscale() ? GetGrayscale() : fRed; }
Float_t GetGreen() const
{ return IsGrayscale() ? GetGrayscale() : fGreen; }
Float_t GetBlue() const
{ return IsGrayscale() ? GetGrayscale() : fBlue; }
Float_t GetHue() const
{ return fHue; }
Float_t GetLight() const
{ return fLight; }
Float_t GetSaturation() const
{ return IsGrayscale() ? 0 : fSaturation; }
Float_t GetAlpha() const
{ return fAlpha; }
Float_t GetGrayscale() const
{ /*ITU*/ return 0.299f*fRed + 0.587f*fGreen + 0.114f*fBlue; }
void SetAlpha(Float_t a)
{ fAlpha = a; }
void HLStoRGB(Float_t h, Float_t l, Float_t s, Float_t& r, Float_t& g, Float_t& b)
{ TColor::HLS2RGB(h, l, s, r, g, b); }
void RGBtoHLS(Float_t r, Float_t g, Float_t b, Float_t& h, Float_t& l, Float_t& s)
{ TColor::RGB2HLS(r, g, b, h, l, s); }