Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
line.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas) and
5 /// draw ROOT 7 lines in it (RLine). It generates a set of lines using the
6 /// "normal" coordinates' system and changing the line color linearly from black
7 /// to red.
8 ///
9 /// \macro_image (line.png)
10 /// \macro_code
11 ///
12 /// \date 2018-03-18
13 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
14 /// is welcome!
15 /// \authors Olivier Couet, Iliana Betsou
16 
17 #include <ROOT/RCanvas.hxx>
18 #include <ROOT/RColor.hxx>
19 #include <ROOT/RLine.hxx>
20 #include <ROOT/RPadPos.hxx>
21 #include "TMath.h"
22 
23 void line()
24 {
25  using namespace ROOT::Experimental;
26 
27  // Create a canvas to be displayed.
28  auto canvas = RCanvas::Create("Canvas Title");
29 
30  for (double i = 0; i < 360; i+=1) {
31  double angle = i * TMath::Pi() / 180;
32  RColor col( 50 + (int) i/360*200, 0, 0);
33  canvas->Draw<RLine>()->SetP1({0.5_normal, 0.5_normal})
34  .SetP2({0.5_normal + 0.3_normal*TMath::Cos(angle), 0.5_normal + 0.3_normal*TMath::Sin(angle)}).AttrLine().SetColor(col);
35  }
36 
37  canvas->Draw<RLine>()->SetP1({0.0_normal, 0.0_normal}).SetP2({1.0_normal,1.0_normal});
38  canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.9_normal,0.1_normal});
39  canvas->Draw<RLine>()->SetP1({0.9_normal, 0.1_normal}).SetP2({0.9_normal,0.9_normal});
40  canvas->Draw<RLine>()->SetP1({0.9_normal, 0.9_normal}).SetP2({0.1_normal,0.9_normal});
41  canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.1_normal,0.9_normal});
42  canvas->Draw<RLine>()->SetP1({0.0_normal, 1.0_normal}).SetP2({1.0_normal,0.0_normal});
43 
44  // canvas->Show();
45  canvas->SaveAs("line.png");
46 }