Logo ROOT   6.18/05
Reference Guide
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
23void 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 RPadPos p(0.3_normal*TMath::Cos(angle) + 0.5_normal,
33 0.3_normal*TMath::Sin(angle) + 0.5_normal);
34 auto opts = canvas->Draw(RLine({0.5_normal, 0.5_normal} , p));
35 RColor col(0.0025*i, 0, 0);
36 opts->SetColor(col);
37 }
38
39 canvas->Draw(RLine({0.0_normal, 0.0_normal}, {1.0_normal,1.0_normal}));
40 canvas->Draw(RLine({0.1_normal, 0.1_normal}, {0.9_normal,0.1_normal}));
41 canvas->Draw(RLine({0.9_normal, 0.1_normal}, {0.9_normal,0.9_normal}));
42 canvas->Draw(RLine({0.9_normal, 0.9_normal}, {0.1_normal,0.9_normal}));
43 canvas->Draw(RLine({0.1_normal, 0.1_normal}, {0.1_normal,0.9_normal}));
44 canvas->Draw(RLine({0.0_normal, 1.0_normal}, {1.0_normal,0.0_normal}));
45
46 // canvas->Show();
47 canvas->SaveAs("line.png");
48}
A color: Red|Green|Blue|Alpha, or a position in a RPalette.
Definition: RColor.hxx:28
TLine * line
Double_t Cos(Double_t)
Definition: TMath.h:629
constexpr Double_t Pi()
Definition: TMath.h:38
Double_t Sin(Double_t)
Definition: TMath.h:625
A position (horizontal and vertical) in a RPad.
Definition: RPadPos.hxx:27