Logo ROOT  
Reference Guide
line.cxx File Reference

Detailed Description

This ROOT 7 example demonstrates how to create a ROOT 7 canvas (RCanvas) and draw ROOT 7 lines in it (RLine). It generates a set of lines using the "normal" coordinates' system and changing the line color linearly from black to red.

#include <ROOT/RCanvas.hxx>
#include <ROOT/RColor.hxx>
#include <ROOT/RLine.hxx>
#include <ROOT/RPadPos.hxx>
#include "TMath.h"
void line()
{
using namespace ROOT::Experimental;
// Create a canvas to be displayed.
auto canvas = RCanvas::Create("Canvas Title");
for (double i = 0; i < 360; i+=1) {
double angle = i * TMath::Pi() / 180;
RColor col( 50 + (int) i/360*200, 0, 0);
canvas->Draw<RLine>()->SetP1({0.5_normal, 0.5_normal})
.SetP2({0.5_normal + 0.3_normal*TMath::Cos(angle), 0.5_normal + 0.3_normal*TMath::Sin(angle)}).AttrLine().SetColor(col);
}
canvas->Draw<RLine>()->SetP1({0.0_normal, 0.0_normal}).SetP2({1.0_normal,1.0_normal});
canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.9_normal,0.1_normal});
canvas->Draw<RLine>()->SetP1({0.9_normal, 0.1_normal}).SetP2({0.9_normal,0.9_normal});
canvas->Draw<RLine>()->SetP1({0.9_normal, 0.9_normal}).SetP2({0.1_normal,0.9_normal});
canvas->Draw<RLine>()->SetP1({0.1_normal, 0.1_normal}).SetP2({0.1_normal,0.9_normal});
canvas->Draw<RLine>()->SetP1({0.0_normal, 1.0_normal}).SetP2({1.0_normal,0.0_normal});
canvas->SetSize(900, 700);
// requires Chrome browser, runs in headless mode
canvas->SaveAs("line.png");
// canvas->Show();
}
Date
2018-03-18
Warning
This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
Authors
Olivier Couet, Iliana Betsou

Definition in file line.cxx.

TMath::Cos
Double_t Cos(Double_t)
Definition: TMath.h:643
ROOT::Experimental::RColor
The color class.
Definition: RColor.hxx:46
RPadPos.hxx
ROOT::Experimental::RCanvas::Create
static std::shared_ptr< RCanvas > Create(const std::string &title)
Create new canvas instance.
Definition: RCanvas.cxx:70
RColor.hxx
RCanvas.hxx
TCanvas::Draw
virtual void Draw(Option_t *option="")
Draw a canvas.
Definition: TCanvas.cxx:841
TMath::Pi
constexpr Double_t Pi()
Definition: TMath.h:43
TPad::SaveAs
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save Pad contents in a file in one of various formats.
Definition: TPad.cxx:5593
TMath::Sin
Double_t Sin(Double_t)
Definition: TMath.h:639
line
TLine * line
Definition: entrylistblock_figure1.C:235
ROOT::Experimental
Definition: RDirectory.hxx:36
TMath.h