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)
14 delete c1;
15
16 c1 = new TCanvas("c1");
17 const Int_t ng = 100;
18 const Int_t kNMAX = 10000;
19 std::vector<Double_t> X(kNMAX), Y(kNMAX);
21 Double_t x = 0, stepx = 0.1;
22
23 while (!gSystem->ProcessEvents()) {
24 if (cursor + ng >= kNMAX) {
25 cursor = 0;
26 for (Int_t i = 0; i < ng; i++) {
27 X[i] = x;
28 Y[i] = TMath::Sin(x);
29 x += stepx;
30 }
31 } else {
32 X[cursor + ng] = x;
33 Y[cursor + ng] = TMath::Sin(x);
34 x += stepx;
35 cursor++;
36 }
37
38 TGraph *g = new TGraph(ng, X.data() + cursor, Y.data() + cursor);
39 g->SetMarkerStyle(21);
40 g->SetMarkerColor(kBlue);
41 g->SetLineColor(kGreen);
42 g->SetBit(kCanDelete); // let canvas delete graph when call TCanvas::Clear()
43
44 c1->Clear();
45 g->Draw("alp");
46 c1->Update();
47
48 gSystem->Sleep(10);
49 }
50}
#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:592