Logo ROOT   6.07/09
Reference Guide
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 
10 void gtime() {
11  TCanvas *c1 = new TCanvas("c1");
12  const Int_t ng = 100;
13  const Int_t kNMAX = 10000;
14  Double_t *X = new Double_t[kNMAX];
15  Double_t *Y = new Double_t[kNMAX];
16  Int_t cursor = kNMAX;
17  TGraph *g = new TGraph(ng);
18  g->SetMarkerStyle(21);
20  Double_t x = 0;
21 
22  while (1) {
23  c1->Clear();
24  if (cursor > kNMAX-ng) {
25  for (Int_t i=0;i<ng;i++) {
26  X[i] = x;
27  Y[i] = sin(x);
28  x += 0.1;
29  }
30  g->Draw("alp");
31  cursor = 0;
32  } else {
33  x += 0.1;
34  X[cursor+ng] = x;
35  Y[cursor+ng] = sin(x);
36  cursor++;
37  g->DrawGraph(ng,&X[cursor],&Y[cursor],"alp");
38  }
39  c1->Update();
41  gSystem->Sleep(10);
42  }
43 }
44 
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:421
return c1
Definition: legend1.C:41
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:747
Double_t x[n]
Definition: legend1.C:17
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:442
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
void Clear(Option_t *option="")
Remove all primitives from the canvas.
Definition: TCanvas.cxx:678
double sin(double)
const Int_t kNMAX
Definition: TCandle.cxx:33
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:45
The Canvas class.
Definition: TCanvas.h:41
double Double_t
Definition: RtypesCore.h:55
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual void DrawGraph(Int_t n, const Int_t *x, const Int_t *y, Option_t *option="")
Draw this graph with new attributes.
Definition: TGraph.cxx:798
Definition: Rtypes.h:61
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183