ROOT logo

From $ROOTSYS/tutorials/graphics/gtime.C

// Example of a graph of data moving in time
// Use the canvas "File/Quit" to exit from this example
//Author: Olivier Couet
void gtime() {
   TCanvas *c1 = new TCanvas("c1");
   const Int_t ng = 100;
   const Int_t kNMAX = 10000;
   Double_t *X = new Double_t[kNMAX];
   Double_t *Y = new Double_t[kNMAX];
   Int_t cursor = kNMAX;
   TGraph *g = new TGraph(ng);
   g->SetMarkerStyle(21);
   g->SetMarkerColor(kBlue);
   Double_t x = 0;
         
   while (1) {
      c1->Clear();
      if (cursor > kNMAX-ng) {
         for (Int_t i=0;i<ng;i++) {
            X[i] = x;
            Y[i] = sin(x);
            x   += 0.1;
         }
         g->Draw("alp");
         cursor = 0;
      } else {
         x + = 0.1;
         X[cursor+ng] = x;
         Y[cursor+ng] = sin(x);
         cursor++;
         g->DrawGraph(ng,&X[cursor],&Y[cursor],"alp");
      }
      c1->Update();
      gSystem->ProcessEvents();
      gSystem->Sleep(10);
   }
}         
      
 gtime.C:1
 gtime.C:2
 gtime.C:3
 gtime.C:4
 gtime.C:5
 gtime.C:6
 gtime.C:7
 gtime.C:8
 gtime.C:9
 gtime.C:10
 gtime.C:11
 gtime.C:12
 gtime.C:13
 gtime.C:14
 gtime.C:15
 gtime.C:16
 gtime.C:17
 gtime.C:18
 gtime.C:19
 gtime.C:20
 gtime.C:21
 gtime.C:22
 gtime.C:23
 gtime.C:24
 gtime.C:25
 gtime.C:26
 gtime.C:27
 gtime.C:28
 gtime.C:29
 gtime.C:30
 gtime.C:31
 gtime.C:32
 gtime.C:33
 gtime.C:34
 gtime.C:35
 gtime.C:36
 gtime.C:37
 gtime.C:38
 gtime.C:39