Logo ROOT   6.12/07
Reference Guide
anim.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphics
3 /// Macro illustrating how to animate a picture using a Timer.
4 ///
5 /// \macro_code
6 ///
7 /// \author Rene Brun
8 
9 #include "TStyle.h"
10 #include "TCanvas.h"
11 #include "TF2.h"
12 #include "TTimer.h"
13 
14 Double_t pi;
15 TF2 *f2;
16 Float_t t = 0;
17 Float_t phi = 30;
18 void anim()
19 {
22  TCanvas *c1 = new TCanvas("c1");
23  c1->SetFillColor(17);
24  pi = TMath::Pi();
25  f2 = new TF2("f2","sin(2*x)*sin(2*y)*[0]",0,pi,0,pi);
26  f2->SetParameter(0,1);
27  f2->SetNpx(15);
28  f2->SetNpy(15);
29  f2->SetMaximum(1);
30  f2->SetMinimum(-1);
31  f2->Draw("glsurf1");
32  TTimer *timer = new TTimer(20);
33  timer->SetCommand("Animate()");
34  timer->TurnOn();
35 }
36 void Animate()
37 {
38  //just in case the canvas has been deleted
39  if (!gROOT->GetListOfCanvases()->FindObject("c1")) return;
40  t += 0.05*pi;
41  f2->SetParameter(0,TMath::Cos(t));
42  phi += 2;
43  gPad->SetPhi(phi);
44  gPad->Modified();
45  gPad->Update();
46 }
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:217
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3320
static constexpr double pi
float Float_t
Definition: RtypesCore.h:53
return c1
Definition: legend1.C:41
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
#define gROOT
Definition: TROOT.h:402
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum value along Y for this function In case the function is already drawn, set also the minimum in the helper histogram.
Definition: TF1.cxx:3294
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:346
constexpr Double_t Pi()
Definition: TMath.h:40
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:316
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:908
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
A 2-Dim function with parameters.
Definition: TF2.h:29
Double_t Cos(Double_t)
Definition: TMath.h:550
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum value along Y for this function In case the function is already drawn, set also the maximum in the helper histogram.
Definition: TF1.cxx:3281
void SetCommand(const char *command)
Set the interpreter command to be executed at time out.
Definition: TTimer.cxx:174
The Canvas class.
Definition: TCanvas.h:31
double Double_t
Definition: RtypesCore.h:55
#define gPad
Definition: TVirtualPad.h:285
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:618
virtual void TurnOn()
Add the timer to the system timer list.
Definition: TTimer.cxx:241