diff --git a/tutorials/graphics/gtime.C b/tutorials/graphics/gtime.C index dddc0d256fa0b..0bf0b5e06f6eb 100644 --- a/tutorials/graphics/gtime.C +++ b/tutorials/graphics/gtime.C @@ -1,7 +1,7 @@ /// \file /// \ingroup tutorial_graphics /// Example of a graph of data moving in time. -/// Use the canvas "File/Quit" to exit from this example +/// Use the canvas "File/Quit ROOT" to exit from this example /// /// \macro_code /// @@ -9,7 +9,7 @@ void gtime() { - auto c1 = (TCanvas*) gROOT->FindObject("c1"); + auto c1 = (TCanvas *) gROOT->FindObject("c1"); if (c1) delete c1; c1 = new TCanvas("c1"); @@ -17,30 +17,33 @@ void gtime() const Int_t kNMAX = 10000; std::vector X(kNMAX), Y(kNMAX); Int_t cursor = kNMAX; - TGraph *g = new TGraph(ng); - g->SetMarkerStyle(21); - g->SetMarkerColor(kBlue); - Double_t x = 0; + Double_t x = 0, stepx = 0.1; - while (1) { - c1->Clear(); - if (cursor > kNMAX-ng) { + while (!gSystem->ProcessEvents()) { + if (cursor + ng >= kNMAX) { + cursor = 0; for (Int_t i = 0; i < ng; i++) { X[i] = x; - Y[i] = sin(x); - x += 0.1; + Y[i] = TMath::Sin(x); + x += stepx; } - g->Draw("alp"); - cursor = 0; } else { - x += 0.1; X[cursor+ng] = x; Y[cursor+ng] = TMath::Sin(x); + x += stepx; cursor++; - g->DrawGraph(ng, X.data()+cursor, Y.data()+cursor, "alp"); } + + TGraph *g = new TGraph(ng, X.data()+cursor, Y.data()+cursor); + g->SetMarkerStyle(21); + g->SetMarkerColor(kBlue); + g->SetLineColor(kGreen); + g->SetBit(kCanDelete); // let canvas delete graph when call TCanvas::Clear() + + c1->Clear(); + g->Draw("alp"); c1->Update(); - if (gSystem->ProcessEvents()) break; + gSystem->Sleep(10); } }