Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
glrose.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// Render a TF2 looking like a rose.
4///
5/// It defines and set a user's palette, and use polar system.
6///
7/// \macro_image(nobatch)
8/// \macro_code
9///
10/// \author Timur Pocheptsov
11
12void glrose()
13{
14 const Int_t paletteSize = 10;
15 Float_t rgb[paletteSize * 3] =
16 {0.80f, 0.55f, 0.40f,
17 0.85f, 0.60f, 0.45f,
18 0.90f, 0.65f, 0.50f,
19 0.95f, 0.70f, 0.55f,
20 1.f, 0.75f, 0.60f,
21 1.f, 0.80f, 0.65f,
22 1.f, 0.85f, 0.70f,
23 1.f, 0.90f, 0.75f,
24 1.f, 0.95f, 0.80f,
25 1.f, 1.f, 0.85f};
26
27 Int_t palette[paletteSize] = {0};
28
29 for (Int_t i = 0; i < paletteSize; ++i)
30 palette[i] = TColor::GetColor(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]);
31
32 gStyle->SetPalette(paletteSize, palette);
33
35 TCanvas *cnv = new TCanvas("glc", "Surface sample", 200, 10, 600, 550);
36
37 TPaveLabel *title = new TPaveLabel(0.04, 0.86, 0.96, 0.98,
38 "\"glsurf2pol\" option + user defined palette.");
39 title->SetFillColor(32);
40 title->Draw();
41
42 TPad *rosePad = new TPad("box", "box", 0.04, 0.04, 0.96, 0.8);
43 rosePad->Draw();
44
45
46 TF2 *fun = new TF2("a", "cos(y)*sin(x)+cos(x)*sin(y)", -6, 6, -6, 6);
47 fun->SetContour(paletteSize);
48 fun->SetNpx(30);
49 fun->SetNpy(30);
50 rosePad->cd();
51 fun->Draw("glsurf2pol");
52}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
The Canvas class.
Definition TCanvas.h:23
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1769
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition TF1.cxx:3446
A 2-Dim function with parameters.
Definition TF2.h:29
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition TF2.cxx:936
virtual void SetContour(Int_t nlevels=20, const Double_t *levels=0)
Set the number and values of contour levels.
Definition TF2.cxx:901
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition TF2.cxx:241
The most important graphics class in the ROOT system.
Definition TPad.h:26
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:603
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1299
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition TStyle.cxx:1782
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:325