Logo ROOT  
Reference Guide
flower.C File Reference

Detailed Description

A demo to show transparency with TMultiGraph (and a really interesting curve/equation). Point compression in TPadPainter. You can see all three flowers ONLY with Cocoa (transparency).

The equation by Paul Burke: http://paulbourke.net/geometry/

#include <cassert>
#include <vector>
#include "TMultiGraph.h"
#include "TVirtualX.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TError.h"
#include "TColor.h"
#include "TMath.h"
#include "customcolor.h"
namespace {
typedef std::vector<Double_t> vector_type;
typedef vector_type::size_type size_type;
//______________________________________________________________________
void create_flower(vector_type &xs, vector_type &ys, size_type nPoints, Double_t r)
{
assert(nPoints > 100 && "create_flower, number of points is too small");
xs.resize(nPoints + 1);
ys.resize(nPoints + 1);
const Double_t angle = 21. * TMath::Pi() / nPoints;
for (size_type i = 0; i <= nPoints; ++i) {
const Double_t u = i * angle;
const Double_t p4 = TMath::Sin(17 * u / 3);
const Double_t p8 = TMath::Sin(2 * TMath::Cos(3 * u) - 28 * u);
const Double_t rr = r * (1 + TMath::Sin(11 * u / 5)) - 4 * p4 * p4 * p4 * p4 * p8 * p8 * p8 * p8 * p8 * p8 * p8 * p8;
xs[i] = rr * TMath::Cos(u);
ys[i] = rr * TMath::Sin(u);
}
}
}//unnamed namespace.
void flower()
{
//0. Indices for custom colors.
Color_t indices[3] = {};
::Error("flower", "failed to create custom colors");
return;
}
//1. I have to create a canvas to initialize gVirtualX.
TCanvas * const cnv = new TCanvas("Chrysanthemum", "Chrysanthemum", 900, 900);
if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) {
::Error("flower", "This macro requires OS X version of ROOT with cocoa enabled");
delete cnv;
return;
}
cnv->cd();//Just to suppress a warning if compiled.
vector_type xs, ys;
//2. Create graphs and custom colors for each graph.
create_flower(xs, ys, 300, 6);
TGraph * const gr1 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]);
new TColor(indices[0], 0., 0., 0.5, "custom_blue", 0.7);
gr1->SetFillColor(indices[0]);
gr1->SetName("part1");
gr1->SetTitle("part1");
create_flower(xs, ys, 500000, 8);
TGraph * const gr2 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]);
new TColor(indices[1], 0.5, 0., 0.5, "custom_purple", 0.5);
gr2->SetFillColor(indices[1]);
gr2->SetName("part2");
gr2->SetTitle("part2");
create_flower(xs, ys, 100000, 10);
TGraph * const gr3 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]);
//If you want to see the difference, change 0.2 to 1 in the next call:
new TColor(indices[2], 1., 0., 0.4, "custom_magenta", 0.2);
gr3->SetFillColor(indices[2]);
gr3->SetName("part3");
gr3->SetTitle("part3");
//3. Create a final multigraph.
//Otcveli, uzh davno ... nu ti ponEl.
TMultiGraph * const flower = new TMultiGraph("Chrysanthemum", "Chrysanthemum");
flower->Add(gr1);
flower->Add(gr2);
flower->Add(gr3);
flower->Draw("AFP");
}
Author
Timur Pocheptsov

Definition in file flower.C.

TGraph::SetTitle
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2324
TMath::Cos
Double_t Cos(Double_t)
Definition: TMath.h:630
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TGraph.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor.h
TVirtualX.h
TCanvas.h
TMultiGraph::Draw
virtual void Draw(Option_t *chopt="")
Draw this multigraph with its current attributes.
Definition: TMultiGraph.cxx:541
ROOT::CocoaTutorials::FindFreeCustomColorIndices
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
Definition: customcolor.h:38
Color_t
short Color_t
Definition: RtypesCore.h:83
TMultiGraph.h
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:43
TColor
Definition: TColor.h:19
TGraph::SetName
virtual void SetName(const char *name="")
Set graph name.
Definition: TGraph.cxx:2308
TCanvas::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:704
customcolor.h
TMath::Sin
Double_t Sin(Double_t)
Definition: TMath.h:626
TMultiGraph
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:36
Double_t
double Double_t
Definition: RtypesCore.h:59
TGraph
Definition: TGraph.h:41
TCanvas
Definition: TCanvas.h:23
TMultiGraph::Add
virtual void Add(TGraph *graph, Option_t *chopt="")
Add a new graph to the list of graphs.
Definition: TMultiGraph.cxx:451
TMath.h
Error
void Error(const char *location, const char *msgfmt,...)
TError.h