Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
14Double_t pi;
15TF2 *f2;
16Float_t t = 0;
17Float_t phi = 30;
18void anim()
19{
20 gStyle->SetCanvasPreferGL(true);
21 gStyle->SetFrameFillColor(42);
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}
36void Animate()
37{
38 // just in case the canvas has been deleted
39 if (!gROOT->GetListOfCanvases()->FindObject("c1"))
40 return;
41 t += 0.05 * pi;
42 f2->SetParameter(0, TMath::Cos(t));
43 phi += 2;
44 gPad->SetPhi(phi);
45 gPad->Modified();
46 gPad->Update();
47}
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
#define gROOT
Definition TROOT.h:417
externTStyle * gStyle
Definition TStyle.h:442
#define gPad
The Canvas class.
Definition TCanvas.h:23
virtual void SetNpx(Int_t npx=100)
virtual void SetMaximum(Double_t maximum=-1111)
virtual void SetMinimum(Double_t minimum=-1111)
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:608
Definition TF2.h:29
void Draw(Option_t *option="") override
Default Draw method for all objects.
virtual void SetNpy(Int_t npy=100)
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:246
void SetCommand(const char *command)
Set the interpreter command to be executed at time out.
Definition TTimer.cxx:179
return c1
Definition legend1.C:41
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
constexpr Double_t Pi()
Definition TMath.h:40