Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
gtime.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// Example of a graph of data moving in time.
4/// Use the canvas "File/Quit ROOT" to exit from this example
5///
6/// \macro_code
7///
8/// \author Olivier Couet
9
10void gtime()
11{
12 auto c1 = (TCanvas *) gROOT->FindObject("c1");
13 if (c1) delete c1;
14
15 c1 = new TCanvas("c1");
16 const Int_t ng = 100;
17 const Int_t kNMAX = 10000;
18 std::vector<Double_t> X(kNMAX), Y(kNMAX);
20 Double_t x = 0, stepx = 0.1;
21
22 while (!gSystem->ProcessEvents()) {
23 if (cursor + ng >= kNMAX) {
24 cursor = 0;
25 for (Int_t i = 0; i < ng; i++) {
26 X[i] = x;
27 Y[i] = TMath::Sin(x);
28 x += stepx;
29 }
30 } else {
31 X[cursor+ng] = x;
32 Y[cursor+ng] = TMath::Sin(x);
33 x += stepx;
34 cursor++;
35 }
36
37 TGraph *g = new TGraph(ng, X.data()+cursor, Y.data()+cursor);
38 g->SetMarkerStyle(21);
39 g->SetMarkerColor(kBlue);
40 g->SetLineColor(kGreen);
41 g->SetBit(kCanDelete); // let canvas delete graph when call TCanvas::Clear()
42
43 c1->Clear();
44 g->Draw("alp");
45 c1->Update();
46
47 gSystem->Sleep(10);
48 }
49}
#define g(i)
Definition RSha256.hxx:105
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kGreen
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
#define X(type, name)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t cursor
const Int_t kNMAX
@ kCanDelete
Definition TObject.h:367
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:588