Logo ROOT  
Reference Guide
transp.C File Reference

Detailed Description

This demo shows how to use transparency. On MacOS X you can see the transparency in a canvas, you can save canvas contents as pdf/png (and thus you'll have an image with transparency on every platform).

//Includes for ACLiC (cling does not need them).
#include "TCanvas.h"
#include "TColor.h"
#include "TError.h"
#include "TStyle.h"
#include "TH1F.h"
//Aux. functions for tutorials/gl.
#include "customcolorgl.h"
void transp()
{
//1. Try to find free indices for our custom colors.
//We can use hard-coded indices like 1001, 1002, 1003, ... but
//I prefer to find free indices in a ROOT's color table
//to avoid possible conflicts with other tutorials.
Int_t indices[2] = {};
::Error("transp", "failed to create new custom colors");
return;
}
//2. Now that we have indices, create our custom colors.
const Int_t redIndex = indices[0], greeIndex = indices[1];
new TColor(redIndex, 1., 0., 0., "red", 0.85);
new TColor(greeIndex, 0., 1., 0., "green", 0.5);
TCanvas * const cnv = new TCanvas("trasnparency", "transparency demo", 600, 400);
TH1F * const hist = new TH1F("a5", "b5", 10, -2., 3.);
TH1F * const hist2 = new TH1F("c6", "d6", 10, -3., 3.);
hist->FillRandom("landau", 100000);
hist2->FillRandom("gaus", 100000);
hist->SetFillColor(redIndex);
hist2->SetFillColor(greeIndex);
cnv->cd();
hist2->Draw();
hist->Draw("SAME");
}
Author
Timur Pocheptsov

Definition in file transp.C.

TStyle::SetCanvasPreferGL
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:325
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1F.h
ROOT::GLTutorials::FindFreeCustomColorIndices
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:40
TStyle.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor.h
TCanvas.h
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TColor
Definition: TColor.h:19
TCanvas::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:704
TH1::FillRandom
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3444
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
customcolorgl.h
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
Error
void Error(const char *location, const char *msgfmt,...)
TError.h