Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rline.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
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_code
10///
11/// \date 2018-03-18
12/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
13/// is welcome!
14/// \authors Olivier Couet, Iliana Betsou
15
16#include <ROOT/RCanvas.hxx>
17#include <ROOT/RColor.hxx>
18#include <ROOT/RLine.hxx>
19#include <ROOT/RPadPos.hxx>
20#include "TMath.h"
21
22void rline()
23{
24 using namespace ROOT::Experimental;
25
26 // Create a canvas to be displayed.
27 auto canvas = RCanvas::Create("RLine example");
28
29 for (double i = 0; i < 360; i+=1) {
30 double angle = i * TMath::Pi() / 180;
31 RColor col( 50 + (int) i/360*200, 0, 0);
32 auto draw = canvas->Draw<RLine>();
33 draw->SetP1({0.5_normal, 0.5_normal});
34 draw->SetP2({0.5_normal + 0.3_normal*TMath::Cos(angle), 0.5_normal + 0.3_normal*TMath::Sin(angle)});
35 draw->line.color = col;
36 }
37
38 canvas->Draw<RLine>()->SetP1({0.0_normal, 0.0_normal}).SetP2({1.0_normal,1.0_normal});
39 canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.9_normal,0.1_normal});
40 canvas->Draw<RLine>()->SetP1({0.9_normal, 0.1_normal}).SetP2({0.9_normal,0.9_normal});
41 canvas->Draw<RLine>()->SetP1({0.9_normal, 0.9_normal}).SetP2({0.1_normal,0.9_normal});
42 canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.1_normal,0.9_normal});
43 canvas->Draw<RLine>()->SetP1({0.0_normal, 1.0_normal}).SetP2({1.0_normal,0.0_normal});
44
45 canvas->SetSize(900, 700);
46
47 if (canvas->SaveAs("line.png"))
48 printf("Store RCanvas in line.png\n");
49
50 canvas->Show();
51}
Option_t Option_t TPoint TPoint angle
The color class.
Definition RColor.hxx:33
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:594
constexpr Double_t Pi()
Definition TMath.h:37
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:588