Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
transparency.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphics
3 /// \notebook
4 /// This macro demonstrates the use of color transparency.
5 ///
6 /// It is done by specifying the alpha value of a given color.
7 /// For instance
8 ///
9 /// ~~~
10 /// ellipse->SetFillColorAlpha(9, 0.571);
11 /// ~~~
12 ///
13 /// changes the ellipse fill color to the index 9 with an alpha value of 0.571.
14 /// 0. would be fully transparent (invisible) and 1. completely opaque (the default).
15 ///
16 /// The transparency is available on all platforms when the flag
17 /// `OpenGL.CanvasPreferGL` is set to `1` in `$ROOTSYS/etc/system.rootrc`, or
18 /// on Mac with the Cocoa backend. X11 does not support transparency. On the file
19 /// output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
20 ///
21 /// \macro_image
22 /// \macro_code
23 ///
24 /// \author Olivier Couet
25 
26 void transparency()
27 {
28  auto c1 = new TCanvas("c1", "c1",224,330,700,527);
29  c1->Range(-0.125,-0.125,1.125,1.125);
30 
31  auto tex = new TLatex(0.06303724,0.0194223,"This text is opaque and this line is transparent");
32  tex->SetLineWidth(2);
33  tex->Draw();
34 
35  auto arrow = new TArrow(0.5555158,0.07171314,0.8939828,0.6195219,0.05,"|>");
36  arrow->SetLineWidth(4);
37  arrow->SetAngle(30);
38  arrow->Draw();
39 
40  // Draw a transparent graph.
41  Double_t x[10] = {
42  0.5232808, 0.8724928, 0.9280086, 0.7059456, 0.7399714,
43  0.4659742, 0.8241404, 0.4838825, 0.7936963, 0.743553};
44  Double_t y[10] = {
45  0.7290837, 0.9631474, 0.4775896, 0.6494024, 0.3555777,
46  0.622012, 0.7938247, 0.9482072, 0.3904382, 0.2410359};
47  auto graph = new TGraph(10,x,y);
48  graph->SetLineColorAlpha(46, 0.1);
49  graph->SetLineWidth(7);
50  graph->Draw("l");
51 
52  // Draw an ellipse with opaque colors.
53  auto ellipse = new TEllipse(0.1740688,0.8352632,0.1518625,0.1010526,0,360,0);
54  ellipse->SetFillColor(30);
55  ellipse->SetLineColor(51);
56  ellipse->SetLineWidth(3);
57  ellipse->Draw();
58 
59  // Draw an ellipse with transparent colors, above the previous one.
60  ellipse = new TEllipse(0.2985315,0.7092105,0.1566977,0.1868421,0,360,0);
61  ellipse->SetFillColorAlpha(9, 0.571);
62  ellipse->SetLineColorAlpha(8, 0.464);
63  ellipse->SetLineWidth(3);
64  ellipse->Draw();
65 
66  // Draw a transparent blue text.
67  tex = new TLatex(0.04871059,0.1837649,"This text is transparent");
68  tex->SetTextColorAlpha(9, 0.476);
69  tex->SetTextSize(0.125);
70  tex->SetTextAngle(26.0);
71  tex->Draw();
72 
73  // Draw two transparent markers
74  auto marker = new TMarker(0.03080229,0.998008,20);
75  marker->SetMarkerColorAlpha(2, .3);
76  marker->SetMarkerStyle(20);
77  marker->SetMarkerSize(1.7);
78  marker->Draw();
79  marker = new TMarker(0.1239255,0.8635458,20);
80  marker->SetMarkerColorAlpha(2, .2);
81  marker->SetMarkerStyle(20);
82  marker->SetMarkerSize(1.7);
83  marker->Draw();
84 
85  // Draw an opaque marker
86  marker = new TMarker(0.3047994,0.6344622,20);
87  marker->SetMarkerColor(2);
88  marker->SetMarkerStyle(20);
89  marker->SetMarkerSize(1.7);
90  marker->Draw();
91 
92 }