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" 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 TGraph *g = new TGraph(ng);
21 g->SetMarkerStyle(21);
22 g->SetMarkerColor(kBlue);
23 Double_t x = 0;
24
25 while (1) {
26 c1->Clear();
27 if (cursor > kNMAX-ng) {
28 for (Int_t i = 0; i < ng; i++) {
29 X[i] = x;
30 Y[i] = sin(x);
31 x += 0.1;
32 }
33 g->Draw("alp");
34 cursor = 0;
35 } else {
36 x += 0.1;
37 X[cursor+ng] = x;
38 Y[cursor+ng] = TMath::Sin(x);
39 cursor++;
40 g->DrawGraph(ng, X.data()+cursor, Y.data()+cursor, "alp");
41 }
42 c1->Update();
43 if (gSystem->ProcessEvents()) break;
44 gSystem->Sleep(10);
45 }
46}
#define g(i)
Definition RSha256.hxx:105
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kBlue
Definition Rtypes.h:66
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
#define gROOT
Definition TROOT.h:405
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
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:440
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:419
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1799
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:586